Skip to content

Commit b94e00a

Browse files
author
Jason Barnett
committed
completes picture scrolls
1 parent 4474806 commit b94e00a

2 files changed

Lines changed: 15 additions & 154 deletions

File tree

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

Lines changed: 0 additions & 140 deletions
This file was deleted.
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,26 @@ <h1>Slide in on Scroll</h1>
5858
};
5959
}
6060

61-
const sliderImages = document.querySelectorAll('.slide-in');
62-
63-
function checkSlide(e) {
64-
sliderImages.forEach(sliderImage => {
65-
// half way through the image
66-
const slideInAt = (window.scrollY + window.innerHeight) - sliderImage.height / 2;
67-
// bottom of the image
68-
const imageBottom = sliderImage.offsetTop + sliderImage.height;
69-
const isHalfShown = slideInAt > sliderImage.offsetTop;
70-
const isNotScrolledPast = window.scrollY < imageBottom;
61+
const sliderImages = document.querySelectorAll('.slide-in')
62+
63+
function checkSlide(e){
64+
sliderImages.forEach(img => {
65+
//halfway thru img
66+
const slideInAt = (window.scrollY + window.innerHeight) - (img.height/2)
67+
//bottom of img
68+
const imgBottom = img.offsetTop + img.height
69+
const isHalfShown = slideInAt > img.offsetTop
70+
const isNotScrolledPast = window.scrollY < imgBottom
71+
7172
if (isHalfShown && isNotScrolledPast) {
72-
sliderImage.classList.add('active');
73+
img.classList.add('active')
7374
} else {
74-
sliderImage.classList.remove('active');
75+
img.classList.remove('active')
7576
}
76-
});
77+
})
7778
}
7879

79-
window.addEventListener('scroll', debounce(checkSlide));
80+
window.addEventListener('scroll', debounce(checkSlide))
8081

8182
</script>
8283

0 commit comments

Comments
 (0)