File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments