in inflation-explorer/shared/js/scrollytellerProgress.js [39:110]
checkScroll() {
if(this.on && this.lastScroll !== window.pageYOffset) {
const bbox = this.scrollText.getBoundingClientRect();
if(!supportsSticky) {
if(bbox.top <= 0 && bbox.bottom >= window.innerHeight) {
this.scrollInner.classed("fixed-top", true);
this.scrollInner.classed("absolute-bottom", false);
this.scrollInner.classed("absolute-top", false);
} else if(bbox.top <= 0) {
this.scrollInner.classed("fixed-top", false);
this.scrollInner.classed("absolute-bottom", true);
this.scrollInner.classed("absolute-top", false);
} else {
this.scrollInner.classed("fixed-top", false);
this.scrollInner.classed("absolute-bottom", false);
this.scrollInner.classed("absolute-top", true);
}
}
const scrollyStartPoint = window.innerHeight * this.triggerTop // point in window at which scrolly is triggered
if(bbox.top < scrollyStartPoint && bbox.bottom > scrollyStartPoint) {
let indx = 0
const neg = Math.floor(Math.abs(bbox.top - (window.innerHeight*(this.triggerTop))))
indx = this.textBoxes.findIndex( (el, j,arr) => {
const soFar = arr.slice(0, j).map( el => el.getBoundingClientRect().height ).reduce(sum, 0)
return soFar > neg
} ) - 1
const i = indx < 0 ? this.textBoxes.length -1 : indx; // default to the last box if box indx is not found
const overallP = (bbox.top - scrollyStartPoint)/bbox.height*(-1)
this.onOverallProgress(overallP)
const prevBox = this.textBoxes[i]
const abs = window.innerHeight*this.triggerTop - prevBox.getBoundingClientRect().top
const total = prevBox.getBoundingClientRect().height
const progressInBox = abs / total;
this.onGradualChange(progressInBox, i, abs, total)
if(i !== this.lastI) {
this.lastI = i;
this.doScrollAction(i);
if(this.transparentUntilActive) {
this.textBoxes.forEach((el, j) => {
if(j <= i) {
el.style.opacity = "1";
} else {
el.style.opacity = "0.25";
}
});
}
}
}
this.lastScroll = window.pageYOffset;
}
window.requestAnimationFrame(this.checkScroll.bind(this));
}