/* FOR COMMENTS ON THE BELOW, PLEASE SEE GENERAL/HOME.JS */ var nLatestKnownScrollY = 0; var bTicking = false; function fOnScrollOrResize() { nLatestKnownScrollY = window.scrollY; fRequestTick(); } window.addEventListener('scroll', fOnScrollOrResize, false); window.addEventListener('resize', fOnScrollOrResize, false); function fRequestTick() { if(!bTicking) { requestAnimationFrame(fUpdateBackgroundPosition); } bTicking = true; } var oTestimonialSection = document.getElementById("testimonial-section"); var oTestimonialSectionParallax = document.getElementById("testimonial-section-parallax"); function fUpdateBackgroundPosition() { var aBoundingRect = oTestimonialSection.getBoundingClientRect(); var nMax = window.innerHeight - aBoundingRect.height; if(aBoundingRect.top >= window.innerHeight) { if(oTestimonialSectionParallax.style!="transform: translateY(0px);") oTestimonialSectionParallax.setAttribute('style', "transform: translateY(0px);min-height:"+aBoundingRect.height+"px;"); } else if(aBoundingRect.top+aBoundingRect.height <= 0) { if(oTestimonialSectionParallax.style!="transform: translateY(-"+nMax+"px);") oTestimonialSectionParallax.setAttribute('style', "transform: translateY(-"+nMax+"px);min-height:"+aBoundingRect.height+"px;"); } else { var nScrolledAmountPercentage = 100 - ((aBoundingRect.top + aBoundingRect.height) / ((window.innerHeight + aBoundingRect.height)/100)); var nYAmount = (nMax/100)*nScrolledAmountPercentage; oTestimonialSectionParallax.setAttribute('style', "transform: translateY(-"+nYAmount+"px);min-height:"+aBoundingRect.height+"px;"); // 0% is aBoundingRect.top equalling window.innerHeight // 100% is aBoundingRect.top+aBoundingRect.Height being less than 0 // One side is between window.innerHeight and 0, the other is aBoundingRect.top+ the same percentage of window.innerHeight } bTicking = false; }