javascript - image placing does not work at first load -


at first laod, image , escape button not appear in designated place. go on , close divs clicking escape button , execute function again. surprisingly, @ second execution, works perfectly. know why results different @ first load?

(firefox)

< html> < head> < style type="text/css"> #wievbackground { position: fixed; top: 0; left: 0; height:100%; width:100%; background-color:red; } #escapebutton { position:fixed; background-color:white; height:40px; width:40px; } < /style> < /head> <body> <div id="wievwrap"> </div> <script type="text/javascript"> function itemview(itemurl) { document.getelementbyid("wievwrap").innerhtml = ' <div id="wievbackground"> </div> '; document.getelementbyid("wievbackground").innerhtml = ' <img id="theitem" style="position:fixed" src="' + itemurl + '"> '; document.getelementbyid("wievbackground").innerhtml += '<div onclick="document.getelementbyid(\'wievwrap\').innerhtml=\'\';" id="escapebutton"></div>'; document.getelementbyid("theitem").style.left = document.getelementbyid("theitem").parentelement.offsetwidth / 2 - document.getelementbyid("theitem").offsetwidth / 2 + "px"; document.getelementbyid("theitem").style.top = document.getelementbyid("theitem").parentelement.offsetheight / 2 - document.getelementbyid("theitem").offsetheight / 2 + "px"; var x = parseint(document.getelementbyid("theitem").style.left) + parseint(document.getelementbyid("theitem").offsetwidth - document.getelementbyid("escapebutton").offsetwidth / 2); document.getelementbyid("escapebutton").style.left = x + "px"; document.getelementbyid("escapebutton").style.top = parseint(document.getelementbyid("theitem").style.top) - document.getelementbyid("escapebutton").offsetheight / 2 + "px"; } </script> <div></div> <div onclick="itemview('smt.png')">function</div> </body> </html>


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -