How do I only console.log(finalPercentage); when the value is different from what it previously was?
Each time I scroll it console logs the same number about 43 times until it changes. I just want it to console.log the number when it changes value.
Is this possible?
scroll.on('scroll', (position) => {
let pageHeight = $('body').height() - $(window).height();
let scrollPos = position.scroll.y;
let scrollPercentage = (scrollPos * 100) / pageHeight;
let finalPercentage = Math.ceil(scrollPercentage);
console.log(finalPercentage);
}