Created
August 10, 2022 18:54
-
-
Save Spellhammer/8e49e656e0b9454092836a61c9261bb5 to your computer and use it in GitHub Desktop.
ScrollActivatedSlidingImageGallery.js
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
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