File: /home/awaldron/_domains/waldroninteractive.com/wp-content/themes/minione/assets/js/headerscroll.js
jQuery(document).ready(function($){
var introSection = $('#sHomeBg'),
introSectionHeight = introSection.height(),
//change scaleSpeed if you want to change the speed of the scale effect
scaleSpeed = 0.3,
//change opacitySpeed if you want to change the speed of opacity reduction effect
opacitySpeed = 1;
//update this value if you change this breakpoint in the style.css file (or _layout.scss if you use SASS)
var MQ = 1170;
triggerAnimation();
$(window).on('resize', function(){
triggerAnimation();
});
//bind the scale event to window scroll if window width > $MQ (unbind it otherwise)
function triggerAnimation(){
$(window).on('scroll', function(){
//The window.requestAnimationFrame() method tells the browser that you wish to perform an animation- the browser can optimize it so animations will be smoother
window.requestAnimationFrame(animateIntro);
});
}
//assign a scale transformation to the introSection element and reduce its opacity
function animateIntro () {
var scrollPercentage = ($(window).scrollTop()/introSectionHeight).toFixed(5);
//check if the introSection is still visible
if( $(window).scrollTop() < introSectionHeight) {
introSection.css({
'opacity': 1 - scrollPercentage*opacitySpeed
});
}
}
});