javascript - Can I run this nested functions in a better way? -


i wondering if run functions in better way, mean don't collection of functions in there :

settimeout(function() {         $(self.header_buttons_classes[0]).addclass(self.animations[15]);         settimeout(function() {             $(self.header_buttons_classes[1]).addclass(self.animations[15]);             settimeout(function() {                 $(self.header_buttons_classes[2]).addclass(self.animations[15]);                 settimeout(function() {                     $(self.header_buttons_classes[3]).addclass(self.animations[15]);                     settimeout(function() {                         $(self.header_buttons_classes[4]).addclass(self.animations[15]);                         settimeout(function() {                             $(self.header_buttons_classes[5]).addclass(self.animations[15]);                         }, 500);                     }, 500);                 }, 500);             }, 500);         }, 500);     }, 500); 

in addition settimeout there setinterval function allows run code every x milliseconds. simplify code follows:

var = 0; var total = self.header_buttons_classes.length; var x = setinterval(function() {     if(i == total) {         clearinterval(x);     } else {         $(self.header_buttons_classes[i]).addclass(self.animations[15]);         i++;     } }, 500); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -