JavaScript variable value to fluctuate between two values -
i'm trying js variable fluctuate between 2 values on time.
for example, let's start var counter = 0
, , every second variable increases one.
how make @ counter == 3
value decreases 1 until counter == -3
, @ point increases again until 3 , down again, , on.
thanks in advance help!
you can :
var counter = 0; var inc = +1; setinterval(function(){ if(counter == 3) inc = -1; if(counter == -3) inc = +1; counter+= inc; }, 1000);
see sample : http://jsfiddle.net/vqfld/3/
Comments
Post a Comment