Skip to content

Instantly share code, notes, and snippets.

@Spellhammer
Created August 10, 2022 18:54
Show Gist options
  • Save Spellhammer/8e49e656e0b9454092836a61c9261bb5 to your computer and use it in GitHub Desktop.
Save Spellhammer/8e49e656e0b9454092836a61c9261bb5 to your computer and use it in GitHub Desktop.
ScrollActivatedSlidingImageGallery.js
var ready = (callback) => {
if(document.readyState != "loading") callback();
else document.addEventListener('DOMContentLoaded', callback);
}
ready( () => {
if( window.angular ) return;
document.addEventListener( 'scroll', throttle( scrollAction, 10 ) );
})
function throttle( callback, limit ) {
let waiting = false;
return function() {
if( !waiting ) {
callback.apply(this.arguments);
waiting = true;
setTimeout( function() {
waiting = false;
}, limit);
}
}
}
function scrollAction() {
let container = document.querySelector('#div_block-10-10');
let firstRow = container.querySelector('div:first-child');
let secondRow = container.querySelector('div:last-child');
firstRow.style.transform = `translateX(-${this.scrollY}px)`;
secondRow.style.transform = `translateX(${this.scrollY}px)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment