javascript實現動態(tài)定制定時器
來源:易賢網 閱讀:1279 次 日期:2015-04-17 10:40:15
溫馨提示:易賢網小編為您整理了“javascript實現動態(tài)定制定時器”,方便廣大網友查閱!

javascript實現動態(tài)定制定時器,具體代碼如下:

function timeout (){

if(typeof timeout._instance === 'object'){

return timeout._instance;

}

function move(time, fn, config) {

function loop() {

fn(config);

time.id = setTimeout(function () {

if (time.num < time.count) {

loop();

time.num++;

} else if (time.num == time.count) {

clearTimeout(self.id);

time.id = null;

time.num = 0;

}

}, time.delay);

}

loop();

}

function stop(time) {

clearTimeout(time.id);

time.id = null;

time.num = 0;

}

timeout._instance = {

on:move,

off:stop

};

return timeout._instance;

};

更多信息請查看IT技術專欄

更多信息請查看腳本欄目
易賢網手機網站地址:javascript實現動態(tài)定制定時器
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網