当前位置: 代码迷 >> Web前端 >> jquery 中的 mouseover ,mouseout 多次触发 解决方法
  详细解决方案

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

热度:436   发布时间:2012-10-11 10:16:10.0
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... } }
  相关解决方案