function mySetInterval(callback, interval) {
var timer = null;
var now = Date.now;
var startTime = now();
var endTime = startTime;
var loop = function() {
timer = requestAnimationFrame(loop); // 使用requestAnimationFrame
endTime = now();
if(endTime - startTime >=interval) {
startTime = endTime = now();
callback && callback(timer);
}
}
timer = requestAnimationFrame(loop);
return timer;
}
var count = 0;
mySetInterval(function(timer){
console.log('超级定时器已部署');
count++;
if(count>=3) {
cancelAnimationFrame(timer);
}
}, 500)