Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

universal-tilt.js

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-tilt.js

Parallax tilt effect library

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
329
decreased by-20.34%
Maintainers
1
Weekly downloads
 
Created
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');

// v1
const tilt = new UniversalTilt(elems, {
  // options...
});

// v2
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.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({
  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: /(Mozilla|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

Package last updated on 05 Mar 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc