我有一个小的"浮动工具箱"-一个有position:fixed; overflow:auto
个的div.
效果很好.
但是,当在该框内滚动(使用鼠标滚轮)并到达底部或顶部时,父元素会"接管""滚动请求":工具箱后面的文档会滚动.
-这很烦人,也不是用户"要求"的.
I'm using jQuery and thought I could stop this behaviour with event.stoppropagation():
$("#toolBox").scroll( function(event){ event.stoppropagation() });
它确实进入了函数,但仍然会发生传播(文档滚动)
Edit:
Working solution thanks to amustill (and Brandon Aaron for the mousewheel-plugin here:
https://github.com/brandonaaron/jquery-mousewheel/raw/master/jquery.mousewheel.js
$(".ToolPage").bind('mousewheel', function(e, d)
var t = $(this);
if (d > 0 && t.scrollTop() === 0) {
e.preventDefault();
}
else {
if (d < 0 && (t.scrollTop() == t.get(0).scrollHeight - t.innerHeight())) {
e.preventDefault();
}
}
});