Skip to content

Instantly share code, notes, and snippets.

@imRohan
Created October 24, 2017 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imRohan/f93a9af3a7254f0d91d5a2fe858bfc57 to your computer and use it in GitHub Desktop.
Save imRohan/f93a9af3a7254f0d91d5a2fe858bfc57 to your computer and use it in GitHub Desktop.
Perspective Transformations Based On Mouse Movement
transformElement(mouseEvent) {
const TRANSFORM_SCALE = 15
const _mouseCoords = {
x: mouseEvent.clientX,
y: mouseEvent.clientY
}
const _window = {
height: window.innerHeight,
width: window.innerWidth
}
const _midpoint = {
x: _window.width / 2,
y: _window.height / 2,
}
const _position = {
x: _mouseCoords.x - _midpoint.x,
y: _mouseCoords.y - _midpoint.y
}
const _movement = {
x: (_position.x / _midpoint.x) * TRANSFORM_SCALE,
y: (_position.y / _midpoint.y) * (-1 * TRANSFORM_SCALE)
}
if (this.loginTransform.enabled) {
this.loginTransform.style = {
transform: `perspective(100vw) rotateY(${_movement.x}deg)`
+ `rotateX(${_movement.y}deg)`,
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment