Volver al ranking

mkosir/react-parallax-tilt

TypeScriptmkosir.github.io/react-parallax-tilt

👀 Easily apply tilt hover effect to React components - lightweight/zero dependencies 2.9kB

parallaxtypescriptreact-libraryreacttiltparallax-effectreact-tiltgyroscope
Crecimiento de estrellas
Estrellas
1.1k
Forks
124
Crecimiento semanal
Issues
0
5001k
ene 2023mar 2024may 2025jul 2026
Artefactosnpmnpm install react-parallax-tilt
README

React Tilt

npm version npm downloads npm bundle size Open issues TypeScript semantic-release

CI CI CI CI CI Codecov Coverage

CI CI

👀 Easily apply tilt hover effects to React components

Live Demo 💥

Install

npm install react-parallax-tilt

Features

  • Lightweight 2.9kB, zero dependencies 📦
  • Tree-shakable 🌳 ESM and CommonJS support
  • Works with React v15 onwards
  • Supports mouse and touch events
  • Support for device tilting (gyroscope)
  • Glare effect 🌟 with custom props (color, position, etc.) 🔗demo
  • Event tracking for component values 📐 (tilt, glare, mousemove, etc.) 🔗demo
  • Multiple built-in effects:
    • Scale on hover 🔗demo
    • Disable x/y axis 🔗demo
    • Flip component vertically/horizontally 🔗demo
    • Window tilt hover effect 🔗demo
    • Manual tilt control 🕹 (via joystick, slider, etc.) 🔗demo
    • Parallax effect for overlaid images 🔗demo

Example

import Tilt from 'react-parallax-tilt';

const App = () => {
  return (
    <Tilt>
      <div style={{ height: '300px', backgroundColor: 'darkgreen' }}>
        <h1>React Parallax Tilt 👀</h1>
      </div>
    </Tilt>
  );
};

Props

All props are optional.
Here's the complete list of available props and their default values:

▶︎ indicates the default value

tiltEnable: boolean ▶︎ true
Enables/disables the tilt effect.

tiltReverse: boolean ▶︎ false
Reverses the tilt direction.

tiltAngleXInitial: number ▶︎ 0
Initial tilt angle (in degrees) on the x-axis.

tiltAngleYInitial: number ▶︎ 0
Initial tilt angle (in degrees) on the y-axis.

tiltMaxAngleX: number ▶︎ 20
Maximum tilt rotation (in degrees) on the x-axis. Range: 0°-90°.

tiltMaxAngleY: number ▶︎ 20
Maximum tilt rotation (in degrees) on the y-axis. Range: 0°-90°.

tiltAxis: 'x' | 'y' ▶︎ undefined
Enables tilt on a single axis only.

tiltAngleXManual: number | null ▶︎ null
Manual tilt rotation (in degrees) on the x-axis.

tiltAngleYManual: number | null ▶︎ null
Manual tilt rotation (in degrees) on the y-axis.

glareEnable: boolean ▶︎ false
Enables/disables the glare effect.

glareMaxOpacity: number ▶︎ 0.7
Maximum glare opacity (0.5 = 50%, 1 = 100%). Range: 0-1

glareColor: string ▶︎ #ffffff
Sets the color of the glare effect.

glarePosition: 'top' | 'right' | 'bottom' | 'left' | 'all' ▶︎ bottom
Sets the position of the glare effect.

glareReverse: boolean ▶︎ false
Reverses the glare direction.

glareBorderRadius: string ▶︎ 0
Sets the border radius of the glare. Accepts any standard CSS border radius value.

scale: number ▶︎ 1
Scale of the component (1.5 = 150%, 2 = 200%).

perspective: number ▶︎ 1000
Defines how far the tilt component appears from the user. Lower values create more extreme tilt effects.

flipVertically: boolean ▶︎ false
Enables/disables vertical flipping of the component.

flipHorizontally: boolean ▶︎ false
Enables/disables horizontal flipping of the component.

reset: boolean ▶︎ true
Determines if effects should reset on onLeave event.

transitionEasing: string ▶︎ cubic-bezier(.03,.98,.52,.99)
Easing function for the transition.

transitionSpeed: number ▶︎ 400
Speed of the transition.

trackOnWindow: boolean ▶︎ false
Tracks mouse and touch events across the entire window.

gyroscope: boolean ▶︎ false
Enables/disables device orientation detection.

onMove: ({ tiltAngleX: number, tiltAngleY: number, tiltAngleXPercentage: number, tiltAngleYPercentage: number, glareAngle: number, glareOpacity: number, event: Event }) => void
Callback triggered when user moves on the component.

onEnter: (event: Event) => void
Callback triggered when user enters the component.

onLeave: (event: Event) => void
Callback triggered when user leaves the component.

Gyroscope - Device Orientation

Please note that device orientation detection is currently experimental technology.
Check the browser compatibility before using it in production.
Important considerations when using device orientation:

  • Always use secure origins (such as https)
  • It may not work in all browsers when used within a cross-origin <iframe> element
Device Orientation on iOS 13+

Apple disabled device motion and orientation by default starting with iOS 12.2.
iOS 13+ provides a permission API to access device orientation events.

When using the gyroscope feature:

<Tilt gyroscope={true}>
  <h1>React Parallax Tilt 👀</h1>
</Tilt>

A permission dialog will prompt the user to allow motion and orientation access at the domain level:

Note: User interaction (like tapping a button) is required to display the permission dialog - it cannot be triggered automatically on page load.

Development

Easily set up a local development environment!

Build project and start storybook on localhost:

  • clone
  • npm install
  • npm start

Start coding! 🎉

Alternative setup using npm link
  1. Clone this repository and navigate to its location

  2. Run the following commands:

    npm install
    npm link # link your local repo to your global packages
    npm run build:watch # build the files and watch for changes
    
  3. Clone the project you want to test with react-parallax-tilt and run:

    npm install
    npm link react-parallax-tilt # link your local copy into this project's node_modules
    npm start
    

Contributing

All contributions are welcome!
Please review contribution guidelines: Pull Requests | Issues

Repositorios relacionados
alexfoxy/lax.js

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

JavaScriptnpmMIT Licenseparallaxscroll
10.5k481
locomotivemtl/locomotive-scroll

🛤 Detection of elements in viewport & smooth scrolling with parallax.

JavaScriptnpmMIT Licensesmooth-scrollingparallax
scroll.locomotive.ca
8.8k1.1k
florent37/MaterialViewPager

A Material Design ViewPager easy to use library

JavaMavenApache License 2.0materialandroid
fiches-plateau-moto.fr
8.1k1.5k
gijsroge/tilt.js

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

JavaScriptnpmMIT Licensetiltjquery
gijsroge.github.io/tilt.js/
3.9k842
nolimits4web/atropos

Stunning touch-friendly 3D parallax hover effects

JavaScriptnpmMIT Licensejavascriptgallery
atroposjs.com
3.6k107
FuYaoDe/react-native-app-intro

react-native-app-intro is a react native component implementing a parallax effect welcome page using base on react-native-swiper , similar to the one found in Google's app like Sheet, Drive, Docs...

JavaScriptnpmMIT Licensereact-nativeparallax
3.3k497
xmuSistone/ViewpagerTransition

viewpager with parallax pages, together with vertical sliding (or click) and activity transition

JavaMavenviewpagertransition
3k502
jscottsmith/react-scroll-parallax

🔮 React hooks and components to create parallax scroll effects for banners, images or any other DOM elements.

TypeScriptnpmMIT Licensereactparallax
react-scroll-parallax.damnthat.tv
3k155
geosigno/simpleParallax.js

Easy Parallax Effect for React & JavaScript

TypeScriptnpmMIT Licenseparallaxsimple
simpleparallax.com
2.2k149
netguru/sticky-parallax-header

A simple React Native library, enabling the creation of fully customized header for your iOS and Android apps.

TypeScriptnpmMIT Licenseopen-sourcecontribution
netguru.github.io/sticky-parallax-header/
2k202
DroidsOnRoids/MPParallaxView

Apple TV Parallax effect in Swift.

SwiftMIT Licenseparallaxswift
1.7k96
AugustRush/ARSegmentPager

segment tab controller with parallax Header

Objective-CMIT Licenseparallax-headerobjective-c
1.7k265