//滚动屏幕 否则容易导致网络的阻塞 思路:1.触发事件2。执行任务3.设置时间间隔(如果时间间隔内有触发行为就取消任务)在时间间后进行循环
//改变时间尺寸
function coloring() {
let r = Math.floor(Math.random() * 255);
let g = Math.floor(Math.random() * 255);
let b = Math.floor(Math.random() * 255);
document.body.style.background = `rgb(${r}, ${g},${b})`;
}
function thirottle(func,delay){//delay 英[dɪˈleɪ]美[dɪˈleɪ]延迟;
let timer;
return function(){
let context = this;
let args =arguments;
if(timer){
return;
}
timer= setTimeout(function(){
func.apply(context,args);//apply方法能劫持另外一个对象的方法,继承另外一个对象的属性
timer = null;
},delay)
}
}
window.addEventListener('resize', thirottle(coloring,2000));
console