2014-01-23 42 views
0

当点击浏览器滚动条时,我的弹出窗口关闭。 我用这个代码关闭弹出:点击浏览器滚动条关闭弹出框

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

我需要弹出没有关闭,当我点击浏览器的滚动条上。

+0

请添加上的jsfiddle你的代码.... – Krish

回答

0

只有滚动条点击(用于滚动条点击黑客代码)

FiddleFromReference

Determine whether user clicking scrollbar or content (onclick for native scroll bar)

检查目标值

唯一机构:

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