javascript - Internet Explorer render issue (simple JS timer - window.setTimeout) -
javascript - Internet Explorer render issue (simple JS timer - window.setTimeout) -
<script language="javascript" type="text/javascript"> var thebar = createprogressbar(document.getelementbyid('progress-bar')); var value; function resetvalue() { value = 0; } function showprogress() { value += 1; thebar.setvalue(value); if (value < 100) { window.settimeout(showprogress, 100); } } window.onload=resetvalue();showprogress(); </script>
--
<script language="javascript" type="text/javascript"> function createprogressbar(elem) { var div1 = document.createelement('div'); div1.classname = 'progress-bar-background'; div1.style.height = elem.offsetheight + 'px'; elem.appendchild(div1); var div2 = document.createelement('div'); div2.classname = 'progress-bar-complete'; div2.style.height = elem.offsetheight + 'px'; div2.style.top = '-' + elem.offsetheight + 'px'; elem.appendchild(div2); homecoming { div1 : div1, div2 : div2, setvalue : function(v) { this.div2.style.width = v + '%'; } } } </script> --
div.field input{ height: 45px; width: 270px; font-size: 24px; } .progress-bar-background { background-color: #d0d0d0; width: 100%; position: relative; overflow:hidden; top: 0; left: 0; } .progress-bar-complete { background-color: green; width: 50%; position: relative; overflow:hidden; top: -12px; left: 0; } #progress-bar { width: auto; height: 10px;; overflow:hidden; border: 0px black solid; } --
this snippet works under chromer, safari , firefox.
the issue net explorer.
it seems render "half-full" , doesn`t execute anything.
since i`m not familiar js have no clue start looking for.
would appreciate noob friendly advice.
change this...
window.onload=resetvalue();showprogress(); to this...
class="lang-js prettyprint-override">window.onload = function() { createprogressbar(); resetvalue(); showprogress(); }; and should fine.
remember... "window.onload" property of window object ... , value of property should function execute automatically 1 time browser has loaded entire dom and content (images, css, js, etc.)
this not place execute stuff -- should utilize event "oncontentloaded" since not uniformly supported across browsers -- should utilize javascript library such jquery or prototype or mootools instead.
but -- of course of study if you're new js -- not skim on in order pleasure of using these libs -- first real taste of javascript , juggle browser incompatibilities -- you'll able appreciate total potential of these libraries.
javascript internet-explorer timer timeout
Comments
Post a Comment