我有一个显示 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