Skip to content

Instantly share code, notes, and snippets.

View Fabiantjoeaon's full-sized avatar

Fabian Fabiantjoeaon

View GitHub Profile
@Fabiantjoeaon
Fabiantjoeaon / windowResize.js
Created August 17, 2016 20:16
Three on window resize
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
window.addEventListener( 'resize', onWindowResize, false );
@Fabiantjoeaon
Fabiantjoeaon / mouseMove.js
Last active October 30, 2016 16:04
Vanilla JS on mousemove. Make sure to add 'data-offset' attribute and specified class to element.
const mouseMoveEls = Array.from(document.getElementsByClassName('transform__mm'));
document.addEventListener( 'mousemove', (e) => {
const width = window.outerWidth;
const height = window.outerHeight;
const offsetX = 0.5 - e.pageX / width;
const offsetY = 0.5 - e.pageY / height;
mouseMoveEls.forEach((el, i) => {
const dataOffset = parseInt(el.getAttribute('data-offset'));
const translate = `translate3d(${Math.round(offsetX * dataOffset)}px, ${Math.round(offsetY * dataOffset)}px, 0px)`;