jQuery 或 Javascript - 如何在不溢出的情况下禁用窗口滚动:隐藏; [英] jQuery or Javascript - how to disable window scroll without overflow:hidden;
问题描述
当我悬停一个元素时,是否可以在不使用 overflow:hidden;
的情况下禁用窗口滚动?
Hi is it possible to disable window scrolling without using overflow:hidden;
when i'm hover an element?
我试过:
$('.chat-content').on('mouseenter',function(){
$(document).scroll(function(e){
if(!$(e).hasClass('.chat-content'))
e.stopPropagation();
e.preventDefault();
});
});
我的意思是,我想让滚动条保持可见,但是当我用鼠标滚动出元素时,窗口不会滚动,而我所在的元素可以滚动
i mean, i want to leave visible the scrollbar but when i scroll out of the element i'm over with mouse the window doesn't scrolls, while the element i'm over can scroll
所以禁用身体滚动而不是元素我不使用css就结束了
So disable scroll for body but not for element i'm over without using css
这是我做的另一个尝试:http://jsfiddle.net/SHwGL/
here is another try i did: http://jsfiddle.net/SHwGL/
推荐答案
尝试在除一个节点之外的所有节点上处理 'mousewheel' 事件
Try to handler 'mousewheel' event on all nodes except one
$('body').on({
'mousewheel': function(e) {
if (e.target.id == 'el') return;
e.preventDefault();
e.stopPropagation();
}
})
演示:http://jsfiddle.net/DHz77/1/
这篇关于jQuery 或 Javascript - 如何在不溢出的情况下禁用窗口滚动:隐藏;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!