Skip to content

Instantly share code, notes, and snippets.

@Spellhammer
Last active January 29, 2023 17:52
Show Gist options
  • Save Spellhammer/e1e1881866598e831e3901963993f80d to your computer and use it in GitHub Desktop.
Save Spellhammer/e1e1881866598e831e3901963993f80d to your computer and use it in GitHub Desktop.
Book landing page video code.
document.querySelectorAll('.mover').forEach( mover => {
if( window.angular ) return;
window.addEventListener('mousemove', (e) => {
if( !calculating ) {
var calculating = setTimeout( () => {
var divisor = mover.getAttribute('speed') ?? 32;
var windowMouseX = (e.clientX - (document.documentElement.clientWidth / 2));
var windowMouseY = (e.clientY - (document.documentElement.clientHeight / 2));
var computedCSS = '';
var translateX = (windowMouseX / divisor) * -1;
var translateY = (windowMouseY / divisor) * -1;
computedCSS += 'transform: translateX(' + translateX + 'px) translateY(' + translateY + 'px);';
mover.style.cssText = computedCSS;
clearTimeout(calculating);
}, 100);
}
})
})
window.addEventListener('scroll', () => {
if( window.angular ) return;
document.querySelectorAll('.spinner').forEach( spinner => {
spinner.style.cssText = 'transform: rotate(' + (-80 + (window.scrollY / 16)) + 'deg)';
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment