简体   繁体   English

单击浏览器滚动条关闭弹出窗口

[英]click on browser scroll bar close popup

When clicking on browser scroll bar my popop window closed. 当点击浏览器滚动条时,我的popop窗口关闭了。 I am used this code for closing popup: 我用这个代码来关闭弹出窗口:

//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();
    }
    });

 });  

And my popup css is: 我的popup 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;
}

I need my popup not closed on when I click on browser's scroll bar. 当我点击浏览器的滚动条时,我需要关闭弹出窗口。

Hopefully this will help you. 希望这会对你有所帮助。

$(document).ready(function(){
    $( window ).scroll(function() {
       $("#popup").hide();
    });
});

Only Scroll bar Click (Hack code for scrollbar click) 仅滚动条单击(用于滚动条单击的哈希代码)

FiddleFromReference FiddleFromReference

Determine whether user clicking scrollbar or content (onclick for native scroll bar) 确定用户是单击滚动条还是内容(onclick用于本机滚动条)

Check target value 检查目标值

Only Body: 只有身体:

 $("body").mouseup(function(e) {

    alert("hi");

}); 

Check particular target 检查特定目标

  $(document).click( function (event) {
  var idName = event.target.id;   // Use  event.target.nodeName
  if(idName == "my_link"){
    return false;
  };
  $('#your_div').fadeOut(350);

});

Except Body Content including Scrollbar 包括滚动条在内的正文内容除外

 $(window).mouseup(function(e) {
 if (e.target == $('html').get(0)) { // Except body content
 alert("hi"); 
 }
 });    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM