File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,28 @@ <h1>Slide in on Scroll</h1>
5858 } ;
5959 }
6060
61+ window . onload = function ( ) {
62+ var imgInfo = [ ] ;
63+
64+ [ ...document . querySelectorAll ( 'img' ) ] . forEach ( ( ele , idx ) => {
65+ imgInfo . push ( {
66+ 'dom' : ele ,
67+ 'top' : ele . offsetTop ,
68+ 'height' : ele . offsetHeight
69+ } )
70+ } )
71+
72+ window . addEventListener ( 'scroll' , e => {
73+ imgInfo . forEach ( ( info , idx ) => {
74+ if ( ( ( window . scrollY ) >= ( info . top + .5 * info . height - window . innerHeight ) ) && ( ( window . scrollY ) <= ( info . top + 1.5 * info . height - .5 * window . innerHeight ) ) ) {
75+ ( info . dom ) . classList . add ( 'active' )
76+ }
77+ else {
78+ ( info . dom ) . classList . remove ( 'active' )
79+ }
80+ } )
81+ } )
82+ }
6183 </ script >
6284
6385 < style >
Original file line number Diff line number Diff line change 161610 . [x] ~~ Hold Shift and Check Checkboxes~~
171711 . [ ] Custom Video Player
181812 . [x] ~~ Key Sequence Detection~~
19- 13 . [ ] Slide in on Scroll
19+ 13 . [x] ~~ Slide in on Scroll~~
202014 . [ ] JavaScript References vs. Copying
212115 . [ ] LocalStorage
222216 . [ ] Mouse Move Shadow
You can’t perform that action at this time.
0 commit comments