Featured post
javascript - determine if an element is scrollable in html document -
hi i'm trying check if html element scrollable.only gecko support needed (and webkit support nice not necessary). documentation tells scrollheight , clientheight same when element has no vertical scrollbar https://developer.mozilla.org/en/dom/element.scrollheight discovered gecko adds margin size scrollheight. so, element margins, scrollheight superior clientheight. https ://bugzilla.mozilla.org/show_bug.cgi?id=576976#c2
so, use like:
var clientheight = element.clientheight; var bordertop = window.getcomputedstyle(element,null).getpropertyvalue('border-top-width'); var borderbottom = window.getcomputedstyle(element,null).getpropertyvalue('border-bottom-width'); var scrollheight = element.scrollheight - parseint(bordertop, 10) - parseint(borderbottom, 10);
it works fine except in 1 case: when use firefox zoom. let's have border of 1px around element. clientheight , scrollheight have difference of 2px (1 top, 1 bottom). unfortunately, window.getcomputedstyle(element,null).getpropertyvalue('border-bottom-width') less 1px when user zooms page.
so, there reliable way determine in firefox if element has scrollbars ?
use offsetheight
instead of clientheight
since includes border, needn't concern that.
- Get link
- X
- Other Apps
Comments
Post a Comment