Last active
March 2, 2021 12:13
-
-
Save eddsaura/fca4c4d8bf1de5362d1d61615532899e to your computer and use it in GitHub Desktop.
Parallax Mouse function with mouseMove for React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The node with the mouseOver event has the background image we are moving | |
const calcParallax = e => { | |
const speed = -0.009 | |
const distX = e.clientX / 2 | |
const distY = e.clientY | |
e.currentTarget.style.backgroundPositionX = `calc(50% + ${(distX * speed)}px)` | |
e.currentTarget.style.backgroundPositionY = `calc(50% + ${(distY * speed)}px)` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment