File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,28 @@ <h1>Slide in on Scroll</h1>
58
58
} ;
59
59
}
60
60
61
+ const sliderImages = document . querySelectorAll ( '.slide-in' ) ;
62
+
63
+ function checkSlide ( e ) {
64
+ sliderImages . forEach ( sliderImage => {
65
+ // half way through image
66
+ const slideInAt = ( window . scrollY + window . innerHeight ) - sliderImage . height / 2 ;
67
+ console . log ( slideInAt ) ;
68
+ // bottom of image
69
+ const imageBottom = sliderImage . offsetTop + sliderImage . height ;
70
+ const isHalfShow = slideInAt > sliderImage . offsetTop ;
71
+ const isNotScrolledPast = window . scrollY < imageBottom ;
72
+ if ( isHalfShow && isNotScrolledPast ) {
73
+ sliderImage . classList . add ( 'active' ) ;
74
+ } else {
75
+ sliderImage . classList . remove ( 'active' ) ;
76
+ }
77
+
78
+ } ) ;
79
+ }
80
+
81
+ window . addEventListener ( 'scroll' , debounce ( checkSlide ) ) ;
82
+
61
83
</ script >
62
84
63
85
< style >
You can’t perform that action at this time.
0 commit comments