Convert Figma logo to code with AI

micku7zu logovanilla-tilt.js

A smooth 3D tilt javascript library.

3,851
172
3,851
25

Top Related Projects

3,815

A tiny 60+fps parallax tilt hover effect for jQuery.

7,064

Lightweight, vanilla javascript parallax library

16,455

Parallax Engine that reacts to the orientation of a smart device

Animate elements as they scroll into view.

10,382

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.

Quick Overview

Vanilla-tilt.js is a lightweight JavaScript library for creating smooth and customizable tilt effects on HTML elements. It provides a simple way to add interactive 3D-like tilting animations to any element on a webpage, enhancing user experience and visual appeal without relying on external dependencies.

Pros

  • Lightweight and performant, with no dependencies
  • Easy to implement and customize
  • Supports both mouse and gyroscope input
  • Extensive configuration options for fine-tuning the tilt effect

Cons

  • Limited to tilt effects only, not a comprehensive animation library
  • May not be suitable for complex 3D transformations
  • Requires JavaScript to be enabled in the browser
  • Might affect accessibility if not implemented carefully

Code Examples

  1. Basic tilt effect:
VanillaTilt.init(document.querySelector(".element"), {
    max: 25,
    speed: 400
});
  1. Tilt effect with custom settings:
VanillaTilt.init(document.querySelector(".element"), {
    max: 35,
    speed: 300,
    glare: true,
    "max-glare": 0.5
});
  1. Applying tilt to multiple elements:
VanillaTilt.init(document.querySelectorAll(".element"));
  1. Destroying a tilt instance:
const element = document.querySelector(".element");
const vanillaTiltInstance = VanillaTilt.init(element);
vanillaTiltInstance.destroy();

Getting Started

  1. Include the vanilla-tilt.js script in your HTML:
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-tilt/1.7.2/vanilla-tilt.min.js"></script>
  1. Add the tilt effect to your desired element:
VanillaTilt.init(document.querySelector(".your-element"), {
    max: 25,
    speed: 400,
    glare: true,
    "max-glare": 0.5
});
  1. Customize the tilt effect by adjusting the options in the second parameter of the init function.

Competitor Comparisons

3,815

A tiny 60+fps parallax tilt hover effect for jQuery.

Pros of tilt.js

  • Lightweight and simple implementation
  • Easy to customize with CSS transforms
  • Supports both jQuery and vanilla JavaScript

Cons of tilt.js

  • Less actively maintained (last update in 2017)
  • Fewer features and options compared to vanilla-tilt.js
  • Limited documentation and examples

Code Comparison

vanilla-tilt.js:

VanillaTilt.init(document.querySelector(".your-element"), {
  max: 25,
  speed: 400,
  glare: true,
  "max-glare": 0.5,
});

tilt.js:

$('.your-element').tilt({
  maxTilt: 25,
  perspective: 1000,
  easing: "cubic-bezier(.03,.98,.52,.99)",
  scale: 1,
  speed: 300,
  transition: true,
  disableAxis: null,
  reset: true,
  glare: false,
  maxGlare: 1
});

Both libraries offer similar functionality for creating tilt effects on elements. vanilla-tilt.js provides a more modern and feature-rich implementation with better performance and customization options. It also has more recent updates and active maintenance. tilt.js, while simpler, may be suitable for projects that require a lightweight solution or have existing jQuery dependencies. However, its lack of recent updates and limited documentation may be drawbacks for some developers.

7,064

Lightweight, vanilla javascript parallax library

Pros of Rellax

  • Lightweight and easy to implement for parallax scrolling effects
  • Supports both horizontal and vertical parallax
  • Offers smooth performance on mobile devices

Cons of Rellax

  • Limited to parallax scrolling effects, less versatile than Vanilla-tilt.js
  • Requires manual adjustment for responsive designs
  • Less active development and community support

Code Comparison

Rellax implementation:

var rellax = new Rellax('.rellax', {
  speed: -2,
  center: false,
  wrapper: null,
  round: true,
  vertical: true,
  horizontal: false
});

Vanilla-tilt.js implementation:

VanillaTilt.init(document.querySelector(".your-element"), {
  max: 25,
  speed: 400,
  glare: true,
  "max-glare": 0.5
});

While Rellax focuses on parallax scrolling effects, Vanilla-tilt.js provides tilt animations. Rellax's code is centered around scroll-based positioning, whereas Vanilla-tilt.js offers more options for tilt behavior and visual effects. Both libraries are relatively simple to implement, but they serve different purposes in web design and interactivity.

16,455

Parallax Engine that reacts to the orientation of a smart device

Pros of Parallax

  • More versatile for creating complex parallax effects with multiple layers
  • Supports both mouse movement and device orientation for parallax
  • Offers a wider range of customization options for scene elements

Cons of Parallax

  • Larger file size and potentially higher performance impact
  • Steeper learning curve due to more complex API and configuration options
  • Less suitable for simple tilt effects on individual elements

Code Comparison

Vanilla-tilt.js:

VanillaTilt.init(document.querySelector(".your-element"), {
  max: 25,
  speed: 400
});

Parallax:

var scene = document.getElementById('scene');
var parallaxInstance = new Parallax(scene, {
  relativeInput: true,
  hoverOnly: true
});

Summary

Vanilla-tilt.js is more lightweight and focused on simple tilt effects, making it easier to implement for basic use cases. Parallax offers more advanced features and flexibility for creating complex parallax scenes, but comes with a larger footprint and steeper learning curve. Choose Vanilla-tilt.js for quick, simple tilt effects on individual elements, and Parallax for more elaborate, multi-layered parallax experiences.

Animate elements as they scroll into view.

Pros of ScrollReveal

  • More versatile, designed for revealing elements on scroll
  • Supports a wider range of animation options and configurations
  • Larger community and more frequent updates

Cons of ScrollReveal

  • Larger file size, potentially impacting page load times
  • Steeper learning curve due to more complex API
  • May be overkill for simple hover or tilt effects

Code Comparison

ScrollReveal:

ScrollReveal().reveal('.element', {
    delay: 200,
    distance: '50px',
    origin: 'bottom',
    duration: 1000
});

vanilla-tilt.js:

VanillaTilt.init(document.querySelector(".element"), {
    max: 25,
    speed: 400,
    glare: true,
    "max-glare": 0.5
});

While ScrollReveal focuses on revealing elements as they enter the viewport, vanilla-tilt.js specializes in creating tilt effects on hover. ScrollReveal offers more customization for scroll-based animations, whereas vanilla-tilt.js provides a simpler API for tilt effects. The choice between the two depends on the specific requirements of your project, with ScrollReveal being more suitable for complex scroll-based animations and vanilla-tilt.js excelling in interactive tilt effects.

10,382

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.

Pros of Waypoints

  • Versatile scroll-based animations and triggers
  • Extensive documentation and examples
  • Supports various frameworks and libraries

Cons of Waypoints

  • Larger file size and potentially higher performance impact
  • Less frequent updates and maintenance

Code Comparison

Vanilla-tilt.js:

VanillaTilt.init(document.querySelector(".your-element"), {
    max: 25,
    speed: 400
});

Waypoints:

var waypoint = new Waypoint({
  element: document.getElementById('your-element'),
  handler: function(direction) {
    console.log('Scrolled to waypoint!')
  }
})

Summary

Vanilla-tilt.js is a lightweight library focused on creating tilt effects for elements, while Waypoints is a more comprehensive solution for scroll-based interactions. Vanilla-tilt.js offers a simpler API and smaller file size, making it ideal for projects that only require tilt effects. Waypoints, on the other hand, provides a wider range of scroll-based functionalities but comes with a larger footprint and potentially more complex implementation.

Choose Vanilla-tilt.js for simple tilt animations or when performance is crucial. Opt for Waypoints when you need diverse scroll-based interactions and have more flexibility in terms of file size and performance overhead.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vanilla-tilt.js

npm version

A smooth 3D tilt javascript library forked from Tilt.js (jQuery version).

View landing page (demos)

Usage

<body>
  
<!-- your markup element -->
<div class="your-element" data-tilt></div>

<!-- at the end of the body -->
<script type="text/javascript" src="vanilla-tilt.js"></script>
</body>

If you want to use this library in IE, you need to include a CustomEvent polyfill: https://github.com/micku7zu/vanilla-tilt.js/issues/49#issuecomment-482711876 or maybe consider the jQuery version.

Options

{
    reverse:                false,  // reverse the tilt direction
    max:                    15,     // max tilt rotation (degrees)
    startX:                 0,      // the starting tilt on the X axis, in degrees.
    startY:                 0,      // the starting tilt on the Y axis, in degrees.
    perspective:            1000,   // Transform perspective, the lower the more extreme the tilt gets.
    scale:                  1,      // 2 = 200%, 1.5 = 150%, etc..
    speed:                  300,    // Speed of the enter/exit transition
    transition:             true,   // Set a transition on enter/exit.
    axis:                   null,   // What axis should be enabled. Can be "x" or "y".
    reset:                  true,   // If the tilt effect has to be reset on exit.
    "reset-to-start":       true,   // Whether the exit reset will go to [0,0] (default) or [startX, startY]
    easing:                 "cubic-bezier(.03,.98,.52,.99)",    // Easing on enter/exit.
    glare:                  false,  // if it should have a "glare" effect
    "max-glare":            1,      // the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
    "glare-prerender":      false,  // false = VanillaTilt creates the glare elements for you, otherwise
                                    // you need to add .js-tilt-glare>.js-tilt-glare-inner by yourself
    "mouse-event-element":  null,   // css-selector or link to an HTML-element that will be listening to mouse events
    "full-page-listening":  false,  // If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
    gyroscope:              true,   // Boolean to enable/disable device orientation detection,
    gyroscopeMinAngleX:     -45,    // This is the bottom limit of the device angle on X axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the left border of the element;
    gyroscopeMaxAngleX:     45,     // This is the top limit of the device angle on X axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the right border of the element;
    gyroscopeMinAngleY:     -45,    // This is the bottom limit of the device angle on Y axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the top border of the element;
    gyroscopeMaxAngleY:     45,     // This is the top limit of the device angle on Y axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the bottom border of the element;
    gyroscopeSamples:       10      // How many gyroscope moves to decide the starting position.
}

Events

const element = document.querySelector(".js-tilt");
VanillaTilt.init(element);
element.addEventListener("tiltChange", callback);

Methods

const element = document.querySelector(".js-tilt");
VanillaTilt.init(element);

// Destroy instance
element.vanillaTilt.destroy();

// Get values of instance
element.vanillaTilt.getValues();

// Reset instance
element.vanillaTilt.reset();

// It also supports NodeList
const elements = document.querySelectorAll(".js-tilt");
VanillaTilt.init(elements);

Install

You can copy and include any of the following file:

NPM

Also available on npm https://www.npmjs.com/package/vanilla-tilt

npm install vanilla-tilt

Import it using

import VanillaTilt from 'vanilla-tilt';

Known issues

Credits

Original library: Tilt.js

Original library author: Gijs Rogé

Contributors

Other projects

Quick Cursor: One-Handed mode (Android app)

Play Store link: https://play.google.com/store/apps/details?id=com.quickcursor

Buy me a beer 🍻

If you want to thank me for vanilla-tilt.js or Quick Cursor Android app, you can donate on PayPal:

License

MIT License

NPM DownloadsLast 30 Days