Home  >  Article  >  Web Front-end  >  When extending the Jquery plug-in to handle mouseover, style flickering occurs when there are child elements inside_jquery

When extending the Jquery plug-in to handle mouseover, style flickering occurs when there are child elements inside_jquery

WBOY
WBOYOriginal
2016-05-16 17:58:321196browse
The solution is as follows:
First, determine whether the current node of the event, that is, jquery's currentTarget, is included in the target, that is, the following extension $.containsNode.
Then, in the mouseover and mouseout events when hover is called, it is judged whether the currentTarget is included in the target, that is, $.fn.fhover extension
The following is the relevant code:
Copy code The code is as follows:

$.containsNode = function(parentNode, childNode) {
if (parentNode.contains) {
return parentNode != childNode && parentNode.contains(childNode);
} else {
return !!(parentNode.compareDocumentPosition(childNode) & 16);
}
}
$ .fn.fhover = function(over, out) {
this.hover(function(e) {
if ($.containsNode(e.target, e.currentTarget)) {
return;
}
over.call(this, e);
}, function(e) {
if ($.containsNode(e.target, e.currentTarget)) {
return;
}
out.call(this, e);
});
return this;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn