2012-07-09 155 views
1

编辑:停止jQuery的滚轮滚动文档

也许我处理这个错误的 - 没有人知道从鼠标滚轮滚动停止页面的方法吗?这甚至可以被禁用?

-

我充满了小格的当鼠标滚轮滚动动画其中一个div容器。这不是一个带溢出的div:hidden,它没有滚动区域 - 它只是一个简单的jquery动画(动画可以很好地工作)。

不幸的是,尽管我尽了最大的努力,但当鼠标位于容器格内时,我无法停止滚动整个页面。

我使用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

和他们都不 帮助。

任何人都可以提供更好的解决方案来解决这个问题吗?

+0

$ .mousewheel犯规滚动元素。它通过鼠标滚轮添加滚动元素。你的例子呢。 (MouseWhell滚动被禁用,滚动条滚动被启用)http://jsfiddle.net/A8tjk/ – kubedan 2012-07-13 08:56:21

+0

这个[answer](http://stackoverflow.com/a/4770179/1107651)给我一个类似的问题为我工作 – 2012-07-12 20:24:05

回答

2

您可以使用galambalazs的solution作为Guilherme Torres Castro answered。但它并不取消scroll事件。如果你想取消滚动事件,你必须添加它。 我的fiddle solutionntownsend's post吸入。

此解决方案的问题是“滑动”(隐藏/显示)滚动条。所以我添加滚动到实际的滚动位置上window.onScroll事件和我FINAL SOLUTION is here

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