简体   繁体   English

打开浏览器菜单时隐藏div

[英]Hide div when browser menu is opened

I want to hide content in div when my webpage window is not active. 我想在我的网页窗口未激活时隐藏div中的内容。 I have tis code in jQuery: 我在jQuery中有tis代码:

$(window).blur(function(){
    $("#context").hide();
});

$(window).focus(function(){
    $("#context").show();
});

It works fine but if open browser menu(menu containing new tab, history... options), context doesn't hide. 它工作正常,但如果打开浏览器菜单(包含新选项卡,历史...选项的菜单),上下文不会隐藏。 Is there any solution for this? 这有什么解决方案吗? Thanks 谢谢

In short, no. 简而言之,没有。 There is no browser API for detecting interaction with native elements. 没有用于检测与本机元素的交互的浏览器API。 The closest you're going to be able to get is to watch for the cursor leaving the window near the part of the browser frame that contains the menu handle. 您最接近的是观察光标离开窗口靠近包含菜单句柄的浏览器框架部分。 However, since each browser places this menu in a different location, you're going to end up getting into a quaqmire of UA detection, timers, and mousemove events to get it right. 但是,由于每个浏览器都将此菜单放在不同的位置,因此您最终会进入UA检测,定时器和mousemove事件的定位,以使其正确。

Solution worked for me: 解决方案对我有用:

$(document).ready(function(){
  $("body").mouseleave(function(){
    $( "#context" ).hide();  
  });
}); 

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

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