(・Θ・) oO( #bigCookie
のclickを連打すれば…… )
コード
timer.js
function Timer(interval, fn) {
this.interval = interval;
this.fn = fn;
this.tm = null;
this.start = function() {
if (!this.tm) {
this.tm = setInterval(fn, this.interval);
}
return this;
};
this.stop = function() {
clearInterval(this.tm);
this.tm = null;
return this;
};
return this;
}
timer.min.js
function Timer(a,b){this.interval=a;this.fn=b;this.tm=null;this.start=function(){if(!this.tm){this.tm=setInterval(b,this.interval)}return this};this.stop=function(){clearInterval(this.tm);this.tm=null;return this};return this};
使用例
どんどこカウント
var count = 0;
window.tm = new Timer(1, function() { console.log(count++); });
window.tm.start();
止める時はwindow.tm.stop()
で。
何かのクッキーを連打
new Timer(100, document.querySelector('#bigCookie').onclick).start();
(^ω^) ?