javascript - Strange Progress Bar Behavior offsetwidth -
i started developing simple progress bar using vanilla javascript. far grabbing width set in css way found js use .offsetwidth - following code functionality demo beginning setup. fiddle link @ bottom of question.
html:
<section id="box"></section> <p> <section id="box2"></section> css:
#box, #box2 { height: 10px; width: 5px; background-color: lightblue; } #box2 { width: 4px; } javascript (onload) :
var savedwidth = document.getelementbyid("box").offsetwidth; alert("box 1 width " + savedwidth); savedwidth = document.getelementbyid("box2").offsetwidth; alert("box 2 width " + savedwidth); while testing out see if grabbed property accurately noticed when width set 5px returned 6px. else seems fine. 4px = 4px, 6px = 6px.
i curious if knew why happened? it's minimal enough won't affect i'm trying seemingly, more know better off you'll be.
fiddle : http://jsfiddle.net/5yk9e5du/
Comments
Post a Comment