Convert Figma logo to code with AI

gijsroge logotilt.js

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

3,815
871
3,815
47

Top Related Projects

A smooth 3D tilt javascript library.

7,064

Lightweight, vanilla javascript parallax library

16,455

Parallax Engine that reacts to the orientation of a smart device

JavaScript, SCSS, Sass, Less, and Stylus helpers for rendering high-resolution image variants

Quick Overview

Tilt.js is a lightweight JavaScript library that adds a tilt effect to HTML elements. It creates a 3D-like perspective effect when hovering over an element, giving depth and interactivity to web pages. The library is easy to use and highly customizable.

Pros

  • Lightweight and performant, with no dependencies
  • Easy to implement with minimal setup required
  • Highly customizable with many configuration options
  • Supports both vanilla JavaScript and jQuery implementations

Cons

  • Limited to tilt effects only, not a comprehensive animation library
  • May not be suitable for all types of websites or design styles
  • Requires JavaScript to function, which may impact accessibility for users with JS disabled
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Basic usage with default options:
const tilt = new Tilt(document.querySelector('.js-tilt'));
  1. Custom options for tilt effect:
const tilt = new Tilt(document.querySelector('.js-tilt'), {
  max: 25,
  speed: 400,
  glare: true,
  'max-glare': 0.5
});
  1. Using with jQuery:
$('.js-tilt').tilt({
  scale: 1.2,
  perspective: 1000
});
  1. Destroying a tilt instance:
const tilt = new Tilt(document.querySelector('.js-tilt'));
tilt.destroy();

Getting Started

  1. Include the Tilt.js library in your HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/tilt.js/1.2.1/tilt.jquery.min.js"></script>
  1. Add the js-tilt class to the element you want to apply the tilt effect to:
<div class="js-tilt">
  <!-- Your content here -->
</div>
  1. Initialize Tilt.js in your JavaScript:
// Vanilla JavaScript
const tilt = new Tilt(document.querySelector('.js-tilt'));

// Or with jQuery
$('.js-tilt').tilt();
  1. Customize the tilt effect by passing options:
const tilt = new Tilt(document.querySelector('.js-tilt'), {
  max: 25,
  speed: 400,
  glare: true,
  'max-glare': 0.5
});

Competitor Comparisons

A smooth 3D tilt javascript library.

Pros of vanilla-tilt.js

  • No dependencies, pure JavaScript implementation
  • Supports more options and customization
  • Actively maintained with recent updates

Cons of vanilla-tilt.js

  • Slightly larger file size
  • May have a steeper learning curve due to more options

Code Comparison

tilt.js:

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

vanilla-tilt.js:

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

Both libraries offer similar core functionality for creating tilt effects on elements. tilt.js is jQuery-dependent, while vanilla-tilt.js is a standalone JavaScript solution. vanilla-tilt.js provides more customization options and features, such as gyroscope support, but may require more setup. tilt.js has a simpler API and might be easier to implement for those already using jQuery. The choice between the two depends on project requirements, existing dependencies, and desired features.

7,064

Lightweight, vanilla javascript parallax library

Pros of Rellax

  • Lightweight and easy to implement
  • Supports both horizontal and vertical parallax scrolling
  • Offers more customization options for speed and direction

Cons of Rellax

  • Limited to parallax scrolling effects only
  • May require more manual adjustments for responsive designs
  • Performance can be affected with many parallax elements

Code Comparison

Rellax implementation:

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

Tilt.js implementation:

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

Rellax focuses on parallax scrolling effects, offering simple implementation for scroll-based animations. It's lightweight and versatile for creating depth in web pages. However, it's limited to scrolling effects and may require more work for responsive designs.

Tilt.js, on the other hand, specializes in creating 3D tilt effects on elements, providing a different kind of interactivity. It's more suited for hover-based animations and can create engaging user experiences for individual elements.

The choice between these libraries depends on the specific effect desired: Rellax for parallax scrolling or Tilt.js for 3D tilt effects on hover.

16,455

Parallax Engine that reacts to the orientation of a smart device

Pros of Parallax

  • More comprehensive parallax effects, including depth and layering
  • Supports multiple input methods (mouse, gyroscope, etc.)
  • Larger community and more frequent updates

Cons of Parallax

  • Heavier library with more dependencies
  • Can be more complex to implement for simple tilt effects
  • May impact performance on slower devices due to its complexity

Code Comparison

Tilt.js:

$('.js-tilt').tilt({
  maxTilt: 20,
  perspective: 1000,
  easing: "cubic-bezier(.03,.98,.52,.99)"
});

Parallax:

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

Summary

Tilt.js is a lightweight library focused specifically on tilt effects, making it easier to implement simple tilt animations. Parallax, on the other hand, offers a more comprehensive set of parallax effects but comes with increased complexity and potential performance considerations. Tilt.js is ideal for projects requiring basic tilt functionality, while Parallax is better suited for more complex, multi-layered parallax animations.

JavaScript, SCSS, Sass, Less, and Stylus helpers for rendering high-resolution image variants

Pros of Retinajs

  • Focuses specifically on handling high-resolution images for retina displays
  • Lightweight and easy to implement for image optimization
  • Automatically detects device pixel ratio and adjusts image sources accordingly

Cons of Retinajs

  • Limited to image handling, unlike Tilt.js which provides interactive tilt effects
  • May require additional markup or data attributes for images
  • Less active development and community support compared to Tilt.js

Code Comparison

Retinajs:

retinajs();
// or with options
retinajs( {check_mime_type: true, force_original_dimensions: false} );

Tilt.js:

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

Summary

Retinajs is a specialized library for handling high-resolution images on retina displays, while Tilt.js focuses on creating interactive tilt effects for elements. Retinajs is simpler to implement for image optimization but has a narrower scope. Tilt.js offers more versatility for creating engaging user interfaces but may be overkill if only image optimization is needed. The choice between the two depends on the specific requirements of the project.

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

Build Status

Tilt.js

A tiny requestAnimationFrame powered 60+fps lightweight parallax tilt effect for jQuery.

Weights just ⚖1.71kb Gzipped Tilt.js demo gif

Take a look at the landing page for demos.

Tilt.js in the wild

Usage

<!DOCTYPE html>
<body>
    <div data-tilt></div> <!-- Tilt element -->
    <script src="jquery.js" ></script> <!-- Load jQuery first -->
    <script src="tilt.js"></script> <!-- Load Tilt.js library -->
</body>

Options

maxTilt:        20,
perspective:    1000,   // Transform perspective, the lower the more extreme the tilt gets.
easing:         "cubic-bezier(.03,.98,.52,.99)",    // Easing on enter/exit.
scale:          1,      // 2 = 200%, 1.5 = 150%, etc..
speed:          300,    // Speed of the enter/exit transition.
transition:     true,   // Set a transition on enter/exit.
disableAxis:    null,   // What axis should be disabled. Can be X or Y.
reset:          true,   // If the tilt effect has to be reset on exit.
glare:          false,  // Enables glare effect
maxGlare:       1       // From 0 - 1.

Events

const tilt = $('.js-tilt').tilt();
tilt.on('change', callback);  // parameters: event, transforms
tilt.on('tilt.mouseLeave', callback); // parameters: event
tilt.on('tilt.mouseEnter', callback); // parameters: event

Methods

const tilt = $('.js-tilt').tilt();

// Destroy instance
tilt.tilt.destroy.call(tilt);

// Get values of instance
tilt.tilt.getValues.call(tilt); // returns [{},{},etc..]

// Reset instance
tilt.tilt.reset.call(tilt);

Install

  • yarn: yarn add tilt.js
  • npm: npm install --save tilt.js

CDN

Alternatives

NPM DownloadsLast 30 Days