Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:58:32
Original
1213 people have browsed it
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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template