Proper syntax for callback on custom javascript function / jQuery -


i've simplified down, , yes... know fadein strange example... part of point.

how make call function on custom function - or function nothing passed through it... example - if there no argument? here fiddle illustrate confusion -

i have broken monster set of callbacks little groups, , want chain them - i'm missing something...

jquery

// example function  function sheriff(speed) {     $('.thing').fadein(speed); }  $('button').on('click', function() {      sheriff(1000, function() {         $('body').css('background-color', 'red');     });  }); 

edit

this actual code, proper callback in place. on simplified first example, , didn't show complicated enough use - , - others i'll leave here.

jquery

function pullinsocialbuttons(speed, callback) {      var facebook    = $('.toy-box-top .social-links li:nth-of-type(1)');     var twitter     = $('.toy-box-top .social-links li:nth-of-type(2)');     var google      = $('.toy-box-top .social-links li:nth-of-type(3)');     var email       = $('.toy-box-top .social-links li:nth-of-type(4)');      facebook.fadein(speed, function() {         twitter.fadein(speed, function() {             google.fadein(speed, function() {                 email.fadein(speed, callback); // callback             });         });     });  } // end 

then in other function --->

$('.some-thing').fadein(500, function() {      pullinsocialbuttons(50, function() {       settimeout(function () {          $('.porthole').fadein(500);        }, 1000);     });  }); 

in sheriff, can receive second param second parameter like

// example function  function sheriff(speed, callback) {     $('.thing').fadein(speed, callback); }  $('button').on('click', function() {      sheriff(1000, function() {         $('body').css('background-color', 'red');     });  }); 

demo: fiddle


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -