We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a35414f commit 156ee6dCopy full SHA for 156ee6d
13 - Slide in on Scroll/index-START.html
@@ -58,6 +58,27 @@ <h1>Slide in on Scroll</h1>
58
};
59
}
60
61
+ const sliderImages = document.querySelectorAll('.slide-in');
62
+
63
+ function checkSlide(e) {
64
+ sliderImages.forEach(img => {
65
+ const slideInAt = (window.scrollY + window.innerHeight) - img.height / 2; // Half way of image.
66
+ const imageBottom = img.offsetTop + img.height; // Bottom of image.
67
68
+ const isHalfShown = slideInAt > img.offsetTop;
69
+ const isNotScrolledPast = window.scrollY < imageBottom;
70
71
+ if(isHalfShown && isNotScrolledPast){
72
+ img.classList.add('active');
73
+ } else {
74
+ img.classList.remove('active');
75
+ }
76
+ })
77
78
79
+ window.addEventListener('scroll', debounce(checkSlide));
80
81
82
</script>
83
84
<style>
0 commit comments