防止滚动“冒泡”从元素到窗口 [英] prevent Scroll "bubbling" from element to window

查看:108
本文介绍了防止滚动“冒泡”从元素到窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含iframe的模式框窗口(弹出窗口),

,而在 iframe 里面有一个 div 可滚动。



当我滚动iframe的内部DIV,并且已经达到其顶部或底部限制时,
浏览器本身的窗口开始滚动。这是一个不想要的行为。



我已经尝试过这样的东西,当鼠标移动时
onMouseEnter进入弹出框区域:



e.preventDefault()由于某种原因不能正常工作...



$ $ $ $ $ $ $$$$$$$$$ b e.preventDefault();
});
})。mouseleave(function(){
$(window).unbind(scroll);
});



更新



e.preventDefault(); 足够...

解决方案

对不起,据我所知,不可能取消任何类型的滚动事件。



W3 MSDN 说:

 可取消
泡沫No

我想你必须离开这个浏览器作者修复。 Firefox(无论如何,Linux上的3.5)对我来说似乎有一个更好的行为:只有当孩子已经在开始使用滚轮的时候已经在顶端/底端,它才滚动父代。 / p>

I have a modal box window (pop-up) that contains an iframe,
and inside that iframe there's a div that is scrollable.

When I scroll the iframe's inner DIV, and it has reached its top or bottom limit,
the window of the browser itself starts to scroll. this is an unwanted behavior.

I've tried something like this, which kills the main window scroll when
onMouseEnter when mouse enters pop-up box area:

e.preventDefault() is not working as it should for some reason...

$("#popup").mouseenter(function(){
   $(window).bind("scroll", function(e){
        e.preventDefault();
   }); 
}).mouseleave(function(){
    $(window).unbind("scroll");
});

Update

Seems like now in 2013 e.preventDefault(); is enough...

解决方案

Sorry, as far as I'm aware it is impossible to cancel any kind of scroll event.

Both W3 and MSDN say:

Cancelable  No
Bubbles     No

I think you'll have to leave this up to browser authors to fix. Firefox (3.5 on Linux, anyway) seems to have a better behaviour for me: it only scrolls the parent if the child is already at the top/bottom end at the moment you start using the scrollwheel.

这篇关于防止滚动“冒泡”从元素到窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆