Disable normal scroll function in jQuery?

Using the mousewheel plugin, I:

$('html, body').bind("mousewheel", function(objEvent, intDelta){
if (intDelta > 0 && $currentPage != 1){
    $currentPage--;
    $('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
else if (intDelta < 0 && $currentPage != 4){
    $currentPage++;
    $('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
});

      

Which works well, but whenever I scroll, it scrolls up or down the page before doing the animation. Is there a way to turn this off? Thank!

+3


source to share


1 answer


Just add

return false;

      

Before the last parenthesis.



$('html, body').bind("mousewheel", function(objEvent, intDelta){
if (intDelta > 0 && $currentPage != 1){
    $currentPage--;
    $('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
else if (intDelta < 0 && $currentPage != 4){
    $currentPage++;
    $('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
return false;
});

      

By the way, you should use .on () instead of .bind ()

+3


source







All Articles