Build a 3D Bank Card with Vanilla-tilt.js
March 12, 2021 • 2 min read
Make your cards stand-out with this quick JavaScript tutorial
THE PROBLEM
The payment form on our website looks a little bit dull. Customers get bored and don’t input their card details. How can we make it more engaging?
A SOLUTION
We are going to use Vanilla-tilt.js to make our card move in 3 dimensions when hovering it with our mouse or tilting our handheld device.
It is really simple:
- Import it in our project
npm install vanilla-tilt
or import it from a CDN as in the example:
import vanillaTilt from "https://cdn.skypack.dev/[email protected]";
- Target a DOM element as a Vanilla-tilt container. The second argument is the options object.
const card = document.querySelector("#card");
VanillaTilt.init(card, { max: 10, speed: 1000, perspective: 700 });
And that’s really it! Here is our final result: