javascript - Dynamically change div height with window resize -
i wanted change height of div when window resized. know can done css using height:100%;
doesn't work on need. wanted make happen in pure javascript without jquery or other framework.
here have done:
<div id="left"> <div id="inner"> </div> </div>
css
#left{ margin-top:40px; width:200px; height:576px; background:white; } #inner{ height:100%; overflow-y:scroll; }
javascript
window.onload= window.onresize=function(){ var left=document.getelementbyid('left'); var window_height = window.innerheight; if ( window_height > 600px ) { left.style.height = document.body.offsetheight +"px"; } else { } }
the div id left has have same margin. wanted change height of div match inner window height (in px no %).
thank you.
window.innerheight
should window.innerheight
(capital h
). note ie doesn't support prior ie9.
also note you're comparing element number here:
if ( left < window_height ) // ^--- element
you wanted height left
instead, condition never true.
Comments
Post a Comment