javascript - setInterval() timings are... off? -


i'm baffled this... appears overly-complex system of setinterval() lines, off tad. maybe timings trying catch up? it's little weird , i'm not sure why.

http://jsfiddle.net/dr3amtw1st/hv3fa/embedded/result/

var number=0; // not change! var key1=true, key2=false, key3=false, key4=false, key5=false; // not change! var key6=false, key7=false, key8=false, key9=false; // not change! var climbspeed=2000; // climbing speed in milliseconds. don't change unless know you're doing. var raised=100; // amount raised far. able changed. var goal=250; // goal, obviously... :p able changed.  var c1=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed); var c2, c3, c4, c5, c6, c7, c8, c9, c10;  var check=setinterval( function() {     if (number>0 && key1==true) {         key1=false;         clearinterval(c1);         climbspeed=1500;         c2=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key2=true;     }     if (number>3 && key2==true) {         key2=false;         clearinterval(c2);         climbspeed=700;         c3=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key3=true;     }     if (number>9 && key3==true) {         key3=false;         clearinterval(c3);         climbspeed=200;         c4=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key4=true;     }     if (number>(.15*raised) && key4==true) {         key4=false;         clearinterval(c4);         climbspeed=100;         c5=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key5=true;     }     if (number>(.20*raised) && key5==true) {         key5=false;         clearinterval(c5);         climbspeed=90;         c6=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key6=true;     }     if (number>(.30*raised) && key6==true) {         key6=false;         clearinterval(c6);         climbspeed=110;         c7=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key7=true;     }     if (number>(raised-20) && key7==true) {         key7=false;         clearinterval(c7);         climbspeed=500;         c8=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key8=true;     }     if (number>(raised-11) && key8==true) {         key8=false;         clearinterval(c8);         climbspeed=650;         c9=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);         key9=true;     }     if (number>=(raised-10) && key9==true) {         key9=false;         clearinterval(c9);         climbspeed=900;         c10=setinterval(function(){document.getelementbyid("amount").innerhtml="$"+number++;},climbspeed);     }     if (number>raised) {         clearinterval(c10);         document.getelementbyid("amount").style.color="red";         //document.getelementbyid("amount").style.fontsize="250px";     } },climbspeed);  function stop() { alert("climbspeed: " + climbspeed + "\n" + "number: " + number + "\n" + "raised: " + raised); //clearinterval(c1); //clearinterval(c2); //clearinterval(c3); //clearinterval(c4); //clearinterval(c5); //clearinterval(c6); //clearinterval(c7); //clearinterval(c8); //clearinterval(c9); //clearinterval(c10); } 

the jsfiddle above looks little off far css goes, think that's jsfiddle itself. looks fine when run 1 document in google chrome (and i've made run in google chrome). 1 time application used on own computer, once, fund raiser thermometer. pay attention number , javascript. want numbers smoother. thought using percentages (.90*raised), have pretty same effect. what's going on here timings , climbspeed? also, buttons @ top debugging purposes. won't in final draft of program.

you setting setinterval multiple times, , it's repeating every 2s. after next 2s make setinterval logic part, it's running double setinterval function. if wish change numbers in save interval, use single settimout function.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -