Set div height to window.innerHeight in JAVASCRIPT -
i wanted set div height of element innerheight of browser. dont want css or jquery take place here. has change height dynamically window resize. made script , not working thought.
here code:
window.onload= window.onresize=function(){ var left = document.getelementbyid("left"); var height = window.innerheight; left.style.height = 'height +('px')'; } can correct code , make work. appreciated.
thank you.
you can add height:500px; left element. , see want. need fit browser height.
solved
//<![cdata[ function resize() { var heights = window.innerheight; document.getelementbyid("left").style.height = heights -50 + "px"; } resize(); window.onresize = function() { resize(); }; //]]> thanks thirumalai murugan's answer.
problem have found window.load may fired before dom element created, can remove html,body css give margin html,body, should handle in javascript if don't want use css, #left css rule used understand div height
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>thirumalai-window size</title> <style type="text/css"> #left{ background:#f00; } html,body{height: 100%;margin: 0px;} </style> </head> <body> <div id="left"></div> <script type="text/javascript">//<![cdata[ function resize() { var heights = window.innerheight; document.getelementbyid("left").style.height = heights + "px"; } resize(); window.onresize = function() { resize(); }; //]]> </script> </body> </html>
Comments
Post a Comment