jquery - JavaScript: how to control progress speed? -


is there option increase , decrease speed of progress? progress takes time , sometime very finish:

var value = 0,     interval = setinterval(function(){     value = ((+value) + .1).tofixed(1);     if(value == 80.5) clearinterval(interval);        $('p').html(value+'%'); },2); 

http://jsfiddle.net/sweetmaanu/zjdbh/13/

you'll note code using setinterval(). global javascript function used periodically executing code @ given time interval. takes 2 arguments typical usage (which way using here). returns unique id can used identify particular interval function (since multiple ones can set simultaneously).

the first argument function executed on interval. function anonymous function:

function() {     value = ((+value) + .1).tofixed(1);     if (value == 80.5) clearinterval(interval);        $('p').html(value + '%'); } 

this function increase percentage progress on each execution.

the second argument integer number number of milliseconds (thousandths of second) let elapse before function first argument executed. key part question, believe. code has 2 (on last line of posted code), wait 2 milliseconds before executing function (which increments percentage progress), , wait 2 more milliseconds, execute same function again, etc.

by changing value of second argument, can change how fast or slow function executes each time, changes how fast or slow percentage increases. if set 500, setinterval wait half second before each execution of function.

you can read other javascript timer functions here, in particular clearinterval(), code uses in anonymous function end interval when reach 80.5%.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -