I have this jquery to mousewheel scroll a div with an id of conentBox. It jerks the page up and down not just the div? i think i need like a bind or something but i dont know?
$(function() {
$('#contentBox').mousewheel(function(event, delta) {
var scrollTop = $(this).scrollTop();
$(this).scrollTop(scrollTop-Math.round(delta * 10));
return false; // prevent default
}); 开发者_JAVA百科
});
Try reducing the amount you add/subtract from the scrollTop:
$(this).scrollTop(scrollTop-Math.round(delta * 2));
Update: It seems that it does work for me in IE7+... I made this demo.
I took a look at Mottie's answer and I've found that I get a much cleaner scroll in general if I put first round delta and then do the multiplication. Like this
$(this).scrollTop(scrollTop-(Math.round(delta) * 2));
Is this the case for you all as well?
精彩评论