JavaScript & jQuery elements movement library based on:
Tilt.js by Gijs Rogé and vanilla-tilt.js by Șandor Sergiu
universal-tilt.js contains additional functions for mobile devices with gyroscope, new Position Base option and more!
Demo
See plugin in action
React plugin
If you use React, install component, with the implementation of the universal-tilt.js library!
More here
How to Install
At the beginning install the library in your project via npm or Yarn:
$ npm install universal-tilt.js
$ yarn add universal-tilt.js
Getting Started
Connect using script tag in HTML:
<script src="/directory/to/library/folder/universal-tilt.js"></script>
Or CommonJS/ES6 import:
const UniversalTilt = require('universal-tilt.js');
import UniversalTilt from 'universal-tilt.js';
Next use library with:
• Vanilla JavaScript e.g:
const elems = document.querySelectorAll('.tilt');
const tilt = new UniversalTilt(elems, {
});
const tilt = UniversalTilt.init(elems, {
});
• or jQuery e.g:
Connect jQuery in HTML
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
or include via command line and CommonJS
$ npm install jquery
$ yarn add jquery
$ bower install jquery
const jQuery = require('jquery');
and call plugin on element
$('.tilt').universalTilt({
});
• Plugin supports autoinit
To use it, add data-tilt
to html element e.g:
<div data-tilt></div>
Methods
• Destroy method
elems.universalTilt.destroy();
Options
Name | Type | Default | Description | Available options |
---|
position-base | string | element | The surface from which the location of the mouse is captured | element or window |
reset | boolean | true | Enable/disable element position reset after mouseout | true (enable), false (disable) |
exclude | RegExp | null | Disable tilt effect on selected user agents | e.g: /(Mozilla|iPad)/ |
shine | boolean | false | Add/remove shine effect on mouseover | true (add), false (remove) |
shine-opacity1 | number | 0 | Add/remove shine effect on mouseover | values >= 0 and <= 1 |
shine-save1 | boolean | false | Save/reset shine effect on mouseout | true (save), false (reset) |
max | number | 35 | Max tilt value | e.g: 28 |
perspective | number | 1000 | Tilt effect perspective | e.g: 700 |
scale | number | 1.0 | Element scale on mouseover | 0.9 /1.3 /etc. |
disabled | string | null | Disable axis | x or y |
reverse | boolean | false | Reverse tilt effect directory | true (reverse directory), false (standard directory) |
speed | number | 300 | Transition speed (ms) | e.g: 500 |
easing | string | cubic-bezier(.03, .98, .52, .99) | Transition easing | cubic-bezier /ease /linear /etc. |
onMouseEnter | function | null | Callback on mouse enter | el => { // code } |
onMouseMove | function | null | Callback on mouse move | el => { // code } |
onMouseLeave | function | null | Callback on mouse leave | el => { // code } |
onDeviceMove2 | function | null | Callback on device move | el => { // code } |
1 shine value must be true
2 mobile value must be true
Event
tiltChange
event will output the x, y & angle of tilting
License
This project is licensed under the MIT License © 2018-present Jakub Biesiada