javascript onmouseout 解决办法
时间:2024-02-26 00:32:44
onmouseout 发现它的触发太敏感,当经过层内文字链时,即触发onmousetout事件,功能不能正常显示,经过一番搜索,整理出来,供大家参考。
1、
<script type="text/javascript">
function test(obj, e) {
if (e.currentTarget) {
if (e.relatedTarget != obj) {
if (obj != e.relatedTarget.parentNode) {
alert(1);
}
}
} else {
if (e.toElement != obj) {
if (obj != e.toElement.parentNode) {
alert(1);
}
}
}
}
</script>
<div onmouseout="test(this, event)" style="width:100px;height:100px;border:1px #666 solid">
<span style="margin:5px;width:100%;height:100%;border:1px #ff0000 solid">faddsf</span></div>
2、
var LeaveFunext = function(t,f){for(var p in f){t[p]=f[p]} return t};
var IE = '\v' == 'v';
var contains = function(wrap,child){
if(IE) return wrap.contains(child);
while(child && typeof(child.parentNode) != "undefind"){
if(wrap == child) return true;
child = child.parentNode;
}
return false;
};
var LeaveFun = function(o){
var _o = typeof o =="string" ? document.getElementById(o) : o;
return this == window ? new LeaveFun(_o):LeaveFunext(_o, LeaveFun.prototype);
};
LeaveFun.prototype = {
mouseleave : function(fn){
if(IE){
this.attachEvent('onmouseleave',fn);
}else{
this.addEventListener('mouseout',function(e){
tar = e.relatedTarget;
if(!contains(this, tar)){
fn.call(this);
}
}, false);
}
return this;
}
};
//调用
LeaveFun('share_customerdiv').mouseleave(function(){document.getElementById('share_customerdiv').style.display ='none';})
3、最简单,但在部分系统上会有轻微闪烁。
<div style="z-index: 11; " onmouseout="this.style.display='none'" onmouseover="this.style.display='block'" >
<b class="STYLE19">更多此人的...</b>
<a class="STYLE8" >留言板</a>
<a class="STYLE8" >好友</a>
<a class="STYLE8"></a>
</div>
标签:javascript,onmouseout
0
投稿
猜你喜欢
Jquery 切换不同图片示例代码
2024-04-16 09:31:33
深度学习入门之Pytorch 数据增强的实现
2021-04-05 22:26:07
Go语言fsnotify接口实现监测文件修改
2024-05-13 10:45:07
Python NumPy实现数组排序与过滤示例分析讲解
2021-07-20 08:33:20
python实现简单的名片管理系统
2022-12-28 21:19:05
Python 含参构造函数实例详解
2023-02-06 13:16:48
Python 下载及安装详细步骤
2021-05-17 05:24:24
基于win2003虚拟机中apache服务器的访问
2023-11-14 11:17:08
JavaScript 获取事件对象的一个注意点
2009-07-24 11:49:00
Centos MySQL 5.7安装、升级教程
2024-01-19 10:24:03
用JavaScript实现PHP的urlencode与urldecode函数
2023-11-23 08:18:14
利用Python求阴影部分的面积实例代码
2021-10-05 15:18:03
IDEA怎么切换Git分支的实现方法
2022-10-11 14:20:21
在ASP.NET 2.0中操作数据之五十四:添加新记录时包含一个文件上传选项
2024-03-16 02:11:24
简单谈谈Python中的反转字符串问题
2022-02-24 11:55:07
python字典嵌套字典的情况下找到某个key的value详解
2021-12-07 12:04:37
Python中的取模运算方法
2023-11-10 04:39:56
MySQL数据表分区策略及优缺点分析
2024-01-22 05:37:19
MySQL 5.0 数据库新特性的存储过程
2007-10-24 19:45:00
MAC版修改MySQL初始密码的方法
2024-01-19 03:19:56