I am trying to implement a functionality where a class is toggled for the body
element on a page with hidden overflow and single screen, based on the amount of scroll. However, there is a challenge: the scrolling behavior involves animation rather than actual scrolling from top.
First, I attempted the following code:
if ($(window).scrollTop() > 1000){
$('body').addClass( "endScroll");
}
else {
$('body').removeClass("endScroll");
}
Unfortunately, this method did not work as expected due to the nature of the single screen with hidden overflow.
Subsequently, I tried a different approach:
$(document).bind('mousewheel', function(e) {
var delta = e.originalEvent.wheelDelta;
if (delta < 0) {
$('body').addClass("endScroll");
} else if (delta > 0) {
$('body').removeClass("endScroll");
}
});
Although this solution successfully adds the class, it does so immediately upon any scrolling action. I am struggling to find a way to toggle the class only after scrolling more than 1000 pixels.
Your help would be greatly appreciated!