惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 李帅斌-Memory

快速导出CSV log4net使用详解 . C# 格式化字符串 web.config中特殊字符的转译 transactionscope的使用 一些概念需要明确的解释一下 还原已清空的回收站 安装卸载Windows服务 Jquery 文章积累 Spring.NET学习——控制反转(基础篇) SqlServer2005导出数据到SqlServer2000步骤! - 李帅斌-Memory - 博客园 MSSQL2005:SQL Server 2005安装图解 网站优化-Gzip压缩 Asp.Net读取excel文件的时候 出错提示:外部表不是预期的格式 解决方案 js触发回车事件 - 李帅斌-Memory - 博客园 VisualStudio用IE8调试时遇到的问题 JQuery+Ajax实现无刷新数据查询 Asp.net页面执行两遍Page_Load的解决方案 C#取硬盘序列号(-备忘-)
在Div中包含的元素移动时,触发div的onmouseout事件.解决方案! - 李帅斌-Memory - 博客园
李帅斌-Memory · 2009-08-06 · via 博客园 - 李帅斌-Memory

我们在做显示隐藏层时,需要使用到onmouseover、onmouseout事件。
问题如下,当层中包含其它元素时,例如层中包含若干个子层,
<div id="dvroot">
      <div id="dvsub1"></div>
      <div id="dvsub1"></div>
</div>
鼠标从dvroot的空白区域,移动到dvsub层中时,我们的要求是dvroot层继续显示,但是,在移动到dvsub时,触发了onmouseout的事件,这时dvroot就会隐藏。针对该问题,在网上搜索了一个完美的解决方案,现记录下来。

以下是做的demo示例,在IE、FF下测试通过。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript div mouseout-hidden-zone</title>

<script>
(function (bool) {
//兼容FF一些方法
    var html;
   
    if (bool) {
   
        html = window.HTMLElement.prototype;
       
        window.__defineGetter__("event", function () {
        //兼容Event对象
            var o = arguments.callee;
           
            do {
           
                if (o.arguments[0] instanceof Event) return o.arguments[0];
           
            } while (o = o.caller);
           
            return null;
       
        });
       
        Event.prototype.__defineGetter__("fromElement", function () {
            return this.relatedTarget;
        });
       
        html.contains = function (o) {
            do {
                if (o == this) return true;
            } while (o = o.parentNode);
            return false;
        };
       
    }
 
})(/Firefox/.test(window.navigator.userAgent));

function hitOneMoreTime(){
  var dvBox = document.getElementById("dvBox");
  
  dvBox.style.display = '';
  dvBox.onmouseout = function(){
   var dvBox = this, e = window.event;
   if(!dvBox.contains(e.toElement || e.fromElement))
   {
    dvBox.style.display = 'none';
   }
  }
 }
</script>
</head>
<body>
<div style="width: 80px; height:30px;border: solid 1px #000;" onclick="hitOneMoreTime()">Click</div>
<div id="dvBox" style="display:none;text-align:center; width: 500px; height:500px; border: solid 1px #d7d; ">
<div><img src='http://www5.mydavinci.com/x/2092/ST' /></div>
</div>
</body>
</html>

 希望对遇到这个问题的朋友有帮助。