javascript - Reliably return element's scrollHeight without using `scrollHeight` property -
using either plain javascript or jquery, need full height of scrolling element. dom property scrollheight is apparently not 100% reliable.
i envisioning temporarily giving item css height of auto, checking out size, returning css prior value (which has problems--how css height:100% instead of height:1012px jquery .css('height') return). figured out due way jquery applies css styling directly element, applying style '' returns normal style-sheet-declared value, theoretically this:
$el.css('height', 'auto'); scrollheight = $el.height(); $el.css('height', ''); but isn't working. height:auto isn't overriding element's original style of 100% , making element take full desired height.
so i'm thinking more along these lines: use position of first child element's top , position of last child element's bottom height. (i can adjust padding , margin if necessary, proof of concept.)
function scrollheight($el) { var lastel = $el.children(':last'); return ( lastel.position().top + lastel.height() - $el.children(':first').position().top; ); } some working in of math.max($el[0].scrollheight, $el.height()) useful...
is terrible idea? can't person who's ever needed know scrollheight of dom element , have reliable, not changing item scrolled, , working in major browsers, ie 8 (though interesting know solution ie 6 & 7).
instead of
$el.css('height', 'auto');
try -
$el.attr('style', 'height: auto !important');
i mention trying becuase -
height:auto isn't overriding element's original style of 100% , making element take full desired height.
Comments
Post a Comment