开发者

Jquery mousewheel scrolling jerks page

开发者 https://www.devze.com 2023-03-05 21:22 出处:网络
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?

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消