当单击浏览器滚动条时,我的弹出窗口关闭。我使用以下代码关闭弹出窗口:
//Closing the pop up when clicked outside of it.
$(document).click(function(e) {
$("#popup").mouseup(function() {
return false;
});
// Bind mouseup event to all the document
$(document).mouseup(function(e) {
// Check if the click is outside the popup
if($(e.target).parents("#popup").length==0 && !$(e.target).is("#popup") && $(e.target).parents(".calendar").length==0) {
// Hide the popup
alert("hi");
$("#popup").hide();
}
});
});
我的弹出式CSS是:
element.style {
display: block;
}
.popupDiv {
background: none repeat scroll 0 0 rgb(245, 245, 245);
border-width: 1px 1px 3px;
padding: 10px 10px 35px;
position: absolute;
right: 0;
top: 85px;
z-index: 999;
}
当我单击浏览器的滚动条时,我需要关闭弹出窗口。
仅滚动条单击(滚动条的提示代码单击)
确定用户是单击滚动条还是单击内容(本机滚动条的onclick)
检查目标值
仅身体:
$("body").mouseup(function(e) {
alert("hi");
});
检查特定目标
$(document).click( function (event) {
var idName = event.target.id; // Use event.target.nodeName
if(idName == "my_link"){
return false;
};
$('#your_div').fadeOut(350);
});
除了正文内容(包括滚动条)
$(window).mouseup(function(e) {
if (e.target == $('html').get(0)) { // Except body content
alert("hi");
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句