A Svelte plugin that implements Vanilla Tilt JS Library features with Svelte/SvelteKit.
Vanilla Tilt Svelte is a Svelte plugin that allows you to easily incorporate the interactive tilt effect from the Vanilla Tilt JS library into your Svelte applications. With this plugin, you can add a subtle and engaging tilt effect to any element on your page, enhancing the user experience and adding a touch of interactivity.
The plugin is built upon the popular Vanilla Tilt JS library, which provides a simple and lightweight solution for adding tilt effects to elements. By integrating Vanilla Tilt JS with Svelte, Vanilla Tilt Svelte makes it effortless to utilize the library's features within your Svelte or SvelteKit projects.
To install Vanilla Tilt Svelte, you can use your preferred package manager. Here are a few examples:
npm install vanilla-tilt-svelte
yarn add vanilla-tilt-svelte
To use Vanilla Tilt Svelte, follow these steps:
svelteTilt
function from the vanilla-tilt-svelte
package in your Svelte component.<script>
import svelteTilt from 'vanilla-tilt-svelte';
</script>
svelteTilt
function as a Svelte directive to the element you want to apply the tilt effect to, passing the desired options as an object.<div use:svelteTilt={{
// Options object
}} />
The svelteTilt
function accepts an options object that allows you to customize the behavior and appearance of the tilt effect. Here are the available options:
reverse
(boolean): Reverse the tilt direction.max
(number): Maximum tilt rotation in degrees.startX
(number): Starting tilt on the X-axis in degrees.startY
(number): Starting tilt on the Y-axis in degrees.perspective
(number): Transform perspective; lower values create a more extreme tilt effect.scale
(number): Scaling factor for the element.speed
(number): Speed of the enter/exit transition.transition
(boolean): Enable or disable the transition on enter/exit.axis
(string|null): Enable tilting on a specific axis ("x" or "y").reset
(boolean): Reset the tilt effect on exit.reset-to-start
(boolean): Choose whether the exit reset goes to [0,0] (default) or [startX, startY].easing
(string): Easing function for the enter/exit transition.glare
(boolean): Enable or disable the "glare" effect.max-glare
(number): Maximum opacity of the "glare" effect (1 = 100%, 0.5 = 50%).glare-prerender
(boolean): Whether to create the glare elements automatically or manually.mouse-event-element
(string|null): CSS selector or link to the HTML element to listen for mouse events.gyroscope
(boolean): Enable or disable device orientation detection using the gyroscope.gyroscopeMinAngleX
(number): The minimum angle on the X-axis that triggers tilt based on gyroscope input.gyroscopeMaxAngleX
(number): The maximum angle on the X-axis that triggers tilt based on gyroscope input.gyroscopeMinAngleY
(number): The minimum angle on the Y-axis that triggers tilt based on gyroscope input.gyroscopeMaxAngleY
(number): The maximum angle on the Y-axis that triggers tilt based on gyroscope input.<div use:svelteTilt={{
reverse: false,
max: 35,
startX: 0,
startY: 0,
perspective: 1000,
scale: 1,
speed: 300,
transition: true,
axis: null,
reset: true,
"reset-to-start": true,
easing: "cubic-bezier(.03,.98,.52,.99)",
glare: false,
"max-glare": 1,
"glare-prerender": false,
"mouse-event-element": null,
gyroscope: true,
gyroscopeMinAngleX: -45,
gyroscopeMaxAngleX: 45,
gyroscopeMinAngleY: -45,
gyroscopeMaxAngleY: 45
}} />
Contributions are welcome! If you would like to contribute to Vanilla Tilt Svelte, please follow these guidelines:
Vanilla Tilt Svelte is released under the ISC License. See the LICENSE file for more information.
âšī¸ Project Information:
Written by @rhpo with â¤ī¸.