javascript - Number-count-up animation in a non-blocking way -


i trying count number target value in animation-like style. environment titanium on ios. follows.

function countnumberup(label) {      label.currentval = label.currentval ? label.currentval : 0;      settimeout(function() {          if (label.currentval < label.targetval) {              label.currentval += 1;              label.settext(label.currentval);              countnumberup(label);          }      }, 5);    }

label instance of ti.ui.label.

first problem see label.settext()-method veeery slow. cool if number counts in rush it's 5 steps per second if vary second parameter of settimeout().

the other thing animation totally blocks die main/ui thread of ios , ui hardly accepts actions until animation has finished. seems settimeout not run in seperate thread.

does of know better way this?

btw. have tried setinterval() doesn't seem better.

try example:

function countnumberup(label){      var interval = setinterval(function(){          if(label.currentval==label.targetval){           clearinterval(interval);           }else{           label.text=label.currentval;           label.currentval++;         }         //remove self-calling contnumberup(label);     }, 50); //5ms delay cause bad performance } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -