首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

jquery 中的 mouseover ,mouseout 多次触发 解决方法

2012-10-11 
jquery 中的 mouseover ,mouseout 多次触发 解决办法?这篇文章分析的不错:http://www.cnblogs.com/shaojun

jquery 中的 mouseover ,mouseout 多次触发 解决办法

?

这篇文章分析的不错:http://www.cnblogs.com/shaojun/archive/2011/03/16/1986249.html

?

?

?

//一下三个函数解决mouseover,mouseout多次触发的问题
??? ??? ??? function contains(parentNode, childNode) {
??? ??? ??? ??? try{
??? ??? ??? ??? ??? if (parentNode.contains) {
??? ??? ??? ??? ??? return parentNode != childNode && parentNode.contains(childNode);
??? ??? ??? ??? ??? } else {
??? ??? ??? ??? ??? return !!(parentNode.compareDocumentPosition(childNode) & 16);
??? ??? ??? ??? ??? }
??? ??? ??? ??? }catch(e){}
??? ??? ??? }???
??? ??? ???
??? ??? ??? function checkHover(e,target){
??? ??? ??? ??? if (getEvent(e).type=="mouseover") {
??? ??? ??? ??? return !contains(target,getEvent(e).relatedTarget||getEvent(e).fromElement) && !((getEvent(e).relatedTarget||getEvent(e).fromElement)===target);
??? ??? ??? ??? } else {
??? ??? ??? ??? return !contains(target,getEvent(e).relatedTarget||getEvent(e).toElement) && !((getEvent(e).relatedTarget||getEvent(e).toElement)===target);
??? ??? ??? ??? }
??? ??? ??? }
??? ??? ???
??? ??? ??? function getEvent(e){
??? ??? ??? ??? return e||window.event;
??? ??? ??? }

?

?

myElement.onmouseover=function(e){    if(checkHover(e,this)){        do someting...    }}myElement.onmouseout=function(e){    if(checkHover(e,this)){        do someting...    }}

热点排行