Socket
Socket
Sign inDemoInstall

universal-tilt.js

Package Overview
Dependencies
1
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    universal-tilt.js

Parallax tilt effect library


Version published
Weekly downloads
460
increased by30.68%
Maintainers
1
Install size
214 kB
Created
Weekly downloads
 

Changelog

Source

2.0.6 (2019-06-17)

Repository Changes
  • platform is now built-in

Readme

Source

universal-tilt.js

NPM version NPM downloads

About

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

First, install the library in your project by npm:

$ npm install universal-tilt.js

Or Yarn:

$ yarn add universal-tilt.js

You can also connect script via one of CDNs:
bundle.run: https://bundle.run/universal-tilt.js
jsDelivr: https://cdn.jsdelivr.net/npm/universal-tilt.js/
unpkg: https://unpkg.com/universal-tilt.js/

Getting Started

Connect libary with project using script tag in HTML:

<script src="/path/to/universal-tilt.js"></script>

ES6 import:

import UniversalTilt from 'universal-tilt.js';

Or CommonJS:

const UniversalTilt = require('universal-tilt.js');

Next use library with:

• Vanilla JavaScript e.g:

const elems = document.querySelectorAll('.tilt');

const tilt = UniversalTilt.init({
  elements: elems,
  settings: {
    // options...
  },
  callbacks: {
    // callbacks...
  }
});

• or jQuery e.g:

Connect jQuery in HTML

<script src="https://code.jquery.com/jquery-3.4.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({
  settings: {
    // options...
  },
  callbacks: {
    // callbacks...
  }
});

• Plugin supports autoinit

To use it, add data-tilt to html element e.g:

<div data-tilt></div>

Methods

• Destroy method

elems.universalTilt.destroy();

• Get values method

elems.universalTilt.getValues();

• Reset method

elems.universalTilt.reset();

Options

Settings

NameTypeDefaultDescriptionAvailable options
basestringelementThe surface from which the location of the mouse is capturedelement or window
disabledstringnullDisable axisx or y
easingstringcubic-bezier(.03, .98, .52, .99)Transition easingcubic-bezier/ease/linear/etc.
excludeRegExpnullDisable tilt effect on selected user agentse.g: /(Firefox|iPad)/
maxnumber35Max tilt valuee.g: 28
perspectivenumber1000Tilt effect perspectivee.g: 700
resetbooleantrueEnable/disable element position reset after mouseouttrue (enable), false (disable)
reversebooleanfalseReverse tilt effect directorytrue (reverse directory), false (standard directory)
scalenumber1.0Element scale on mouseover0.9/1.3/etc.
shinebooleanfalseAdd/remove shine effect on mouseovertrue (add), false (remove)
shine-opacity1number0Add/remove shine effect on mouseovervalues >= 0 and <= 1
shine-save1booleanfalseSave/reset shine effect on mouseouttrue (save), false (reset)
speednumber300Transition speed (ms)e.g: 500

Callbacks

NameDescriptionAvailable options
onDestroyCallback on plugin destroyel => { /* code */ }
onDeviceMove2Callback on device moveel => { /* code */ }
onInitCallback on plugin initel => { /* code */ }
onMouseEnterCallback on mouse enterel => { /* code */ }
onMouseLeaveCallback on mouse leaveel => { /* code */ }
onMouseMoveCallback on mouse moveel => { /* code */ }

1 shine value must be true
2 only for devices supported device motion

Event

tiltChange event will output the x, y & angle of tilting

License

This project is licensed under the MIT License © 2018-present Jakub Biesiada

Keywords

FAQs

Last updated on 17 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc