Created
November 10, 2021 11:47
-
-
Save peterkarn/d6d3279ae976c53c99e37d2b7bf4a30b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //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