Skip to content

Instantly share code, notes, and snippets.

@peterkarn
Created November 10, 2021 11:47
Show Gist options
  • Select an option

  • Save peterkarn/d6d3279ae976c53c99e37d2b7bf4a30b to your computer and use it in GitHub Desktop.

Select an option

Save peterkarn/d6d3279ae976c53c99e37d2b7bf4a30b to your computer and use it in GitHub Desktop.
//animated section
function throttle(fn, wait) {
let time = Date.now();
return function() {
if (time + wait - Date.now() < 0) {
fn();
time = Date.now()
}
}
}
function checkScroll() {
var picturesSection = document.querySelector('.pictures-section');
var picturesSectionOffset = picturesSection.getBoundingClientRect().top;
const scrolled = wrapper.scrollTop;
scrolled > picturesSectionOffset ? picturesSection.classList.add("animated") : picturesSection.classList.remove("animated")
}
wrapper.addEventListener("scroll", throttle(checkScroll, 300));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment