function () { returnthis. Map (function() { var) . offsetParent | | Docelem; while (OffsetParent && (!jquery.nodename (offsetParent, "html") && Jquery.css (offsetParent, "position") = = = "Static" )) { = offsetparent.offsetparent; } return OffsetParent | | Docelem; }); }
The code is relatively simple, first it returns THIS.MAP (function () {}) so the return is an array ...
Gets the offsetparent of the current element, if not documentelement
Jquery.nodename ("OffsetParent", "html") is to determine whether the current offsetParent is HTML, and then Jquery.css (offsetParent, "position") = = = " Static ") to determine whether the offsetparent is static ...
But when the problem comes, when is the while true?
(!jquery.nodename (offsetParent, "HTML") excludes HTML, but there's a body we can't ignore.
And then I found out.
Console.log (document.getElementById (' div '). offsetParent); Console.log ($ (' #div '). OffsetParent ());
Native returns body and jquery returns HTML
The reason, just asked on the StackOverflow, indeed, whether jquery returns HTML or body is not important, anyway, is that the current element does not have a fixed ancestor element, and jquery returned to the HTML reason, probably want to do a standardization bar.
(Ps~stackoverflow quite to the force Ah, the other answer tomorrow to watch again, go back to break sleep ... )
jquery offsetParent () Source code interpretation