File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,15 @@ <h2 class="color-1 weight-title-h font-title section__title center">A codeful of
325325
326326function checkScrollAnimations ( ) {
327327
328+ featurePoints . forEach ( point => {
329+
330+ const visible = isScrolledIntoView ( point ) ;
331+
332+ point . classList . toggle ( 'visible' , visible ) ;
333+
334+ } ) ;
335+
336+ /*
328337 // window scroll position
329338 const scrolled = window.scrollY || window.pageYOffset;
330339
@@ -340,7 +349,24 @@ <h2 class="color-1 weight-title-h font-title section__title center">A codeful of
340349 }
341350
342351 });
352+ */
353+
354+ }
355+
356+ function isScrolledIntoView ( el ) {
357+
358+ const rect = el . getBoundingClientRect ( ) ;
359+ const elemTop = rect . top ;
360+ const elemBottom = rect . bottom ;
361+
362+ // Only completely visible elements return true:
363+ const isVisible = ( elemTop >= 0 ) && ( elemBottom <= window . innerHeight ) ;
364+
365+ // Partially visible elements return true:
366+ // isVisible = elemTop < window.innerHeight && elemBottom >= 0;
343367
368+ return isVisible ;
369+
344370}
345371
346372window . addEventListener ( 'scroll' , checkScrollAnimations ) ;
You can’t perform that action at this time.
0 commit comments