MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / checkSlide

Function checkSlide

assets/js/ImageSlide.js:18–35  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

16const sliderImages = document.querySelectorAll('.slide-in');
17
18function checkSlide(e) {
19 sliderImages.forEach(sliderImage => {
20 //half way through the image
21 const slideInAt = (window.scrollY + window.innerHeight) - sliderImage.height/2;
22 // bottom of the image
23 const imageBottom = sliderImage.offsetTop + sliderImage.height;
24 const isHalfShown = slideInAt > sliderImage.offsetTop;
25 const isNotScrolledPast = window.scrollY < imageBottom;
26 if (isHalfShown && isNotScrolledPast)
27 {
28 sliderImage.classList.add('active');
29 }
30 else{
31 sliderImage.classList.remove('active');
32 }
33
34 });
35}
36
37window.addEventListener('scroll', debounce(checkSlide));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected