我有一个小的"浮动工具箱"-一个有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();
        }
    }
});

推荐答案

使用布兰登·亚伦的Mousewheel plugin是可能的.

这里有一个演示:http://jsbin.com/jivutakama/edit?html,js,output

$(function() {

  var toolbox = $('#toolbox'),
      height = toolbox.height(),
      scrollHeight = toolbox.get(0).scrollHeight;

  toolbox.bind('mousewheel', function(e, d) {
    if((this.scrollTop === (scrollHeight - height) && d < 0) || (this.scrollTop === 0 && d > 0)) {
      e.preventDefault();
    }
  });

});

Javascript相关问答推荐

是否有方法在OpenWeatherMap API中获取过go 的降水数据?

为什么从liveWire info js代码传递数组我出现错误?

角色 map 集/spritebook动画,用户输入不停止在键上相位器3

如何修复(或忽略)HTML模板中的TypeScript错误?'

如何使用JavaScript将文本插入空div

在拖放时阻止文件打开

如何从html元素创建树 struct ?

如何使onPaste事件与可拖动的HTML元素一起工作?

我在Django中的视图中遇到多值键错误

从另一个数组中的对应行/键值对更新数组中的键值对对象

当我点击一个按钮后按回车键时,如何阻止它再次被点击

在查看网页时,如何使HTML中的按钮工作方式类似于鼠标上的滚轮或箭头键?

与在编剧中具有动态价值的定位器交互

使用Perl Selify::Remote::Driver执行Java脚本时出错

将以前缓存的 Select 器与querySelector()一起使用

每隔一行文本段落进行镜像(Boustrophedon)

JavaScript -如何跳过某个字符(S)来打乱字符串中的字符

为什么我的InDesign Java脚本不能完全工作?

此上下文在JavaScript中

我如何才能阻止我的球数以指数方式添加到我的HTML画布中?