Skip to content

Instantly share code, notes, and snippets.

@eddsaura
Last active March 2, 2021 12:13
Show Gist options
  • Save eddsaura/fca4c4d8bf1de5362d1d61615532899e to your computer and use it in GitHub Desktop.
Save eddsaura/fca4c4d8bf1de5362d1d61615532899e to your computer and use it in GitHub Desktop.
Parallax Mouse function with mouseMove for React
// 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