Created
October 24, 2017 20:30
-
-
Save imRohan/f93a9af3a7254f0d91d5a2fe858bfc57 to your computer and use it in GitHub Desktop.
Perspective Transformations Based On Mouse Movement
This file contains 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
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