足球游戏_中国足彩网¥体育资讯$

javascript实现鼠标移出事件onmouseout
来源:易贤网 阅读:1679 次 日期:2015-04-22 11:06:50
温馨提示:易贤网小编为您整理了“javascript实现鼠标移出事件onmouseout”,方便广大网友查阅!

最近在做一个简单的鼠标onmouseover时显示层(层里面有多个链接文字),onmouseout 时隐藏层的功能时,发现有诸多问题,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>

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看脚本栏目
易贤网手机网站地址:javascript实现鼠标移出事件onmouseout
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标