【发布时间】: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