Skip to content

Commit e4b66a0

Browse files
committed
scroll
1 parent cbb7008 commit e4b66a0

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
@@ -60,24 +60,25 @@ <h1>Slide in on Scroll</h1>
6060

6161
const sliderImages = document.querySelectorAll('.slide-in');
6262

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;
63+
function checkSlide(e){
64+
//half image
65+
sliderImages.forEach(slideImage =>{
66+
const slideInAt = (window.scrollY + window.innerHeight) - slideImage.height/2;
67+
//bottom of the image
68+
const imageBottom = slideImage.offsetTop + slideImage.height;
69+
const isHalfShown = slideInAt > slideImage.offsetTop;
70+
// console.log(isHalfShown);
7071
const isNotScrolledPast = window.scrollY < imageBottom;
72+
console.log(isNotScrolledPast);
7173
if (isHalfShown && isNotScrolledPast) {
72-
sliderImage.classList.add('active');
73-
} else {
74-
sliderImage.classList.remove('active');
74+
slideImage.classList.add('active');
75+
}else{
76+
slideImage.classList.remove('active');
7577
}
76-
});
78+
});
7779
}
7880

79-
window.addEventListener('scroll', debounce(checkSlide));
80-
81+
window.addEventListener('scroll',debounce(checkSlide));
8182
</script>
8283

8384
<style>

0 commit comments

Comments
 (0)