-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Description
https://github.com/jquery/jquery/blob/master/src/css/hiddenVisibleSelectors.js
All versions seem to get this wrong for inline elements. For example, anchors with images inside them on Chrome return an offsetWidth and offsetHeight of 0. This is likely because offsetWidth/Height are based on a Working Draft Spec: http://dev.w3.org/csswg/cssom-view/#dom-htmlelement-offsetwidth which does not yet define a CSS Layout Box well ( http://dev.w3.org/csswg/cssom-view/#css-layout-box ) and when it does, only includes elements whose 'display' property that is 'table-column' or 'table-column-group'.
Since current implementations of offsetWidth/Height on most browsers are much more performant than getClientRects/getBoundingClientRect ( http://jsperf.com/offsetwidth-vs-getclientrects-vs-getboundingclientrect ), it makes since to use them, but only when they return non-falsy values.
A performant version of this function should be run:
function (elem) {
//Expand list of displays as spec is finished, is window.getComputedStyle needed here?
var hasLayoutBox = ['table-column', 'table-column-group'].indexOf(elem.style.display) > -1;
return (
!elem.offsetWidth &&
(hasLayoutBox || !elem.getBoundingClientRect().width)
) || (
!elem.offsetHeight &&
(hasLayoutBox || !elem.getBoundingClientRect().height)
);
}