26 lines
941 B
JavaScript
26 lines
941 B
JavaScript
$( document ).ready( function () {
|
|
|
|
document.addEventListener( 'scroll', scrolled );
|
|
|
|
let revealables = document.querySelectorAll( '.reveal' );
|
|
|
|
let currentlyShowing = Math.floor( window.scrollY / ( window.innerHeight / revealables.length + 50 ) );
|
|
|
|
|
|
for ( let i = 0; i < currentlyShowing; i++ ) {
|
|
if ( i < parseInt( revealables.length ) ) {
|
|
revealables[ i ].classList.add( 'active' );
|
|
}
|
|
}
|
|
|
|
function scrolled() {
|
|
let regPos = Math.floor( window.scrollY / ( window.innerHeight / revealables.length + 50 ) );
|
|
if ( regPos < currentlyShowing && regPos < parseInt( revealables.length ) ) {
|
|
revealables[ regPos ].classList.remove( 'active' );
|
|
} else if ( regPos > currentlyShowing && regPos < parseInt( revealables.length ) + 1 ) {
|
|
revealables[ currentlyShowing ].classList.add( 'active' );
|
|
}
|
|
currentlyShowing = regPos;
|
|
}
|
|
} );
|