Skip to content

Commit 3f4228f

Browse files
committed
Lesson 13 complete.
1 parent f8e2062 commit 3f4228f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

13 - Slide in on Scroll/index-START.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ <h1>Slide in on Scroll</h1>
5858
};
5959
}
6060

61+
const sliderImages = document.querySelectorAll('.slide-in');
62+
63+
function checkSlide(event) {
64+
sliderImages.forEach(function(sliderImage) {
65+
const slideInAt = (window.scrollY + window.innerHeight) - (sliderImage.height / 2);
66+
const imageBottom = sliderImage.offsetTop + sliderImage.height;
67+
const isHalfShown = slideInAt > sliderImage.offsetTop;
68+
const isNotScrolledPast = window.scrollY < imageBottom;
69+
if (isHalfShown && isNotScrolledPast) {
70+
sliderImage.classList.add('active');
71+
} else {
72+
sliderImage.classList.remove('active');
73+
}
74+
})
75+
}
76+
77+
window.addEventListener('scroll', debounce(checkSlide));
78+
6179
</script>
6280

6381
<style>

0 commit comments

Comments
 (0)