javascript - scrollHeight not working with position:absolute -
javascript - scrollHeight not working with position:absolute -
i trying retrieve body's scrollheight in order reset size of div id="background1". if in external css set id position:absolute scrollheight returns 0. if set position:relative scrollheight gives me right value. there of course of study many more selectors in css 1 other of set position:absolute - leaving such doesn't alter above behavior. code :
<script type="text/javascript"> function getelement(elem) { var art; if ( document.all ) { // way old msie versions work fine art = document.all[elem]; } else if ( document.layers ) { // way nn4 works fine art = document.layers[elem]; } else if ( document.getelementbyid ) { // way standards work fine art = document.getelementbyid( elem ); } homecoming art; } function togglearticledisplay(elem) { var artarray = document.getelementsbytagname("article"); for(var = 0; < artarray.length; i++) { artarray[i].style.display = "none"; } var fine art = getelement(elem); art.style.display = "block"; var bg1 = document.getelementbyid("background1"); bg1.style.height = "550px"; var b = document.getelementbyid("potoococha"); alert(b.scrollheight); bg1.style.height = (b.scrollheight >= window.innerheight) ? (b.scrollheight+20) + "px" : window.innerheight + "px"; } </script> </head> <body id="potoococha" onload="togglearticledisplay('hometext')"> <div id="background1" style="height:615px;"/>
and css :
div#background1 { position : absolute; left : 45px; top : 0px; z-index : 1; width : 50px; background-color : rgba(182,181,91,1.0); }
merely changing position relative makes javascript function alert homecoming proper scrollheight need absolute other reasons. scrollheight not work if element absolutely positioned? said there later absolutely positioned element doesn't have effect on scrollheight's homecoming value. element first kid of body element seems problem. ideas?
this kinda dirty hack, seek this:
bg1.style.position = "relative"; var savedheight = b.scrollheight; bg1.style.position = "absolute";
not sure if that'll work, maybe give try.
javascript html css
Comments
Post a Comment