Created
June 13, 2011 02:27
-
-
Save kanreisa/1022243 to your computer and use it in GitHub Desktop.
Countdown - Call Function When Finished Countdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Countdown - Call Function When Finished Countdown | |
**/ | |
var Countdown = Class.create({ | |
initialize: function(pInitialValue, pFunction){ | |
this.i = pInitialValue; | |
this.f = pFunction; | |
}, | |
turn: function(){ | |
--this.i; | |
if(this.i == 0){ | |
this.f(); | |
} | |
} | |
}); | |
/* 使い方の例: | |
var urls = [ | |
'http://example.cdn/A.lib.js', | |
'http://example.cdn/B.lib.js', | |
'http://example.cdn/C.lib.js' | |
]; | |
var hoge = new Countdown(urls.length, function(){ | |
alert('done!'); | |
}); | |
urls.each(function(url){ | |
//ここにロードするコードをかく | |
hoge.turn();//Ajax.Request完了時に呼ぶとかonloadで呼ぶとか | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment