【问题标题】:stop the jquery scrollwheel scrolling the document停止滚动文档的jquery滚轮
【发布时间】:2012-07-08 23:55:50
【问题描述】:

编辑:

也许我正在接近这个错误 - 有谁知道阻止页面用鼠标滚轮滚动的任何方法?这甚至可以禁用吗?

--

我有一个 div 容器,里面装满了较小的 div,当鼠标滚轮滚动时会产生动画。这不是一个具有溢出:隐藏的 div,它没有滚动区域 - 它只是一个简单的 jquery 动画(顺便说一句,动画效果很好)。

不幸的是,尽管我尽了最大努力,当鼠标在容器 div 内时,我仍无法阻止整个页面滚动。

我正在使用 Brandon Aaron 的 jQuery 鼠标滚轮插件(它应该可以解决我的问题,但不幸的是它没有)。

这是我的 javascript:

$('#containerDiv').mousewheel(function(event,delta,deltaX,deltaY){
    /* all of this is supposed to stop the page from scrolling...  but it doesnt*/
    event.bubbles=false;
    event.cancelBubble=true;
    if(event.preventDefault) event.preventDefault();
    if(event.stopPropagation) event.stopPropagation();
    if(event.stopImmediatePropagation) event.stopImmediatePropagation();
    $(document).blur();
    $(this).focus();

    /*this function just animates the divs inside the container divs*/
    animateDivs(delta);
});

我已经解决了这些问题:

Prevent scrolling of parent element?

stop mousewheel's continued effect

stop scrolling of webpage with jquery

他们似乎都没有帮助。

谁能为这个问题提供更好的解决方案?

【问题讨论】:

  • 这个answer 对我有用的类似问题
  • $.mousewheel 不滚动元素。它通过鼠标滚轮添加滚动元素。你的例子确实如此。 (鼠标滚轮滚动被禁用。滚动条滚动被启用)jsfiddle.net/A8tjk

标签: jquery scroll mousewheel


【解决方案1】:

您可以将 galambalazs 的solution 用作Guilherme Torres Castro answered。但它不会取消scroll 事件。如果要取消滚动事件,则必须添加它。 我的fiddle solution 灵感来自ntownsend's post

此解决方案的问题是“闪烁”(隐藏/显示)滚动条。所以我在 window.onScroll 事件和我的FINAL SOLUTION is here

上添加滚动到实际滚动位置

当我尝试滚动时最终解决方案有问题,但事件 beforeScroll 不存在https://stackoverflow.com/a/3352244/1102223

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多