Reputation: 187
Using the mousewheel plugin, I have:
$('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 fine, but whenever I scroll, it scrolls up or down the page a tick first before doing the animation. Is there any way to disable this? Thanks!
Upvotes: 3
Views: 610
Reputation: 5590
Just add a
return false;
Before the last brace.
$('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;
});
BTW, you should use .on() instead of .bind()
Upvotes: 3