JS: Detecting wrapped inline elements?
I have a indefinite amount of in-line elements being output. Now, depending on browser width, some elements will, of course, wrap to a new line. Is it possible to detect and single out these rows of elements or does the dom just see it as one large line?
Thanks for the help!!
EDIT: Trying to detect wrapped elements via offset height(Thanks Matchu). Wrapped elements output same values开发者_JS百科(total height of the element) as those found on the first row though. Any reason why?
$('#content').children().each(function() {
alert($(this)[0].offsetHeight);
});
You can check the offsetHeight
property of the elements and watch for it to jump. When an inline element has a greater offsetHeight
than the previous element, this element is on a new line.
element.getClientRects() when done on an inline element that is wrapped will return an array, with an rect object for each line. Bowser support is limited.
No, it's not possible directly. You could only try to measure the width of each element, compute the position and process the ones that don't fit.
精彩评论