使用滚动条时防止 mousedown 功能
我有一个显示链接 onclick 的 div,我想在 div 外部单击鼠标时隐藏(类似于大多数模式框功能) - 问题是,当用户使用浏览器滚动条时,这被认为是单击并隐藏 div
这是我用来显示 div 的内容,
$('.trigger').click(function(e){
e.preventDefault();
open_slideout(this);
});
function open_slideout(el){
$(document).unbind('mousedown');
//code here to display the div if its not already shown
//close on click-out
$(document).bind('mousedown',function(){
$(panel_id).removeClass('active').hide('fast');
$(el).removeClass('active');
});
$('.panel.active').bind('mousedown',function(e){e.stopPropagation();});
$('.trigger').bind('mousedown',function(e){e.stopPropagation();});
}
因此如果他们在活动区域内单击,我设置了 stopPropagation,但就像我说的,如果他们使用滚动条,它会隐藏 div
I've got a div that shows onclick for a link and I want to hide when the mouse is clicked outside the div (similar to most modal box functionality) - the problem is that when the user uses the browser scrollbar, that is considered a click and hides the div
this is what i use to show the div
$('.trigger').click(function(e){
e.preventDefault();
open_slideout(this);
});
function open_slideout(el){
$(document).unbind('mousedown');
//code here to display the div if its not already shown
//close on click-out
$(document).bind('mousedown',function(){
$(panel_id).removeClass('active').hide('fast');
$(el).removeClass('active');
});
$('.panel.active').bind('mousedown',function(e){e.stopPropagation();});
$('.trigger').bind('mousedown',function(e){e.stopPropagation();});
}
so I've set the stopPropagation if they click within the active area, but like I said, if they use the scrollbar it hides the div
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎已经成功了:
this seems to have done the trick: