laipower/wp-content/plugins/gp-premium/elements/assets/js/parallax.js
2020-04-07 13:03:04 +00:00

18 lines
695 B
JavaScript

function generate_parallax_element( selector, context ) {
context = context || document;
var elements = context.querySelectorAll( selector );
return Array.prototype.slice.call( elements );
}
window.addEventListener( "scroll", function() {
var scrolledHeight= window.pageYOffset;
generate_parallax_element( ".page-hero" ).forEach( function( el, index, array ) {
var limit = el.offsetTop + el.offsetHeight;
if( scrolledHeight > el.offsetTop && scrolledHeight <= limit ) {
el.style.backgroundPositionY = ( scrolledHeight - el.offsetTop ) / hero.parallax + "px";
} else {
el.style.backgroundPositionY = "0";
}
});
});