Last active
August 29, 2015 14:09
-
-
Save GZShi/de30952cbb29099e7adb to your computer and use it in GitHub Desktop.
定时秒杀
This file contains hidden or 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
/** | |
* 1. 更改日期和时间设置 | |
* 2. Internet 时钟 | |
* 3. 更改设置 | |
* 4. time.pool.aliyun.com | |
* 5. 立即更新 | |
* 6. 确定 | |
*/ | |
/** | |
* 定时秒杀 | |
* @author LeiFeng | |
* @param {Number} time 秒杀时间 | |
* @param {Function} todo 秒杀操作 | |
*/ | |
function timeTODO(time, todo) { | |
var now = Date.now(); | |
if(now >= time) { | |
todo.call(null); | |
} else { | |
setTimeout(timeTODO.bind(null, time, todo), (time-now) >> 1); | |
} | |
} | |
timeTODO(+new Date('2014/11/11 00:00:00'), function () { | |
// 买!买!买!!! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment