版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
// //防抖
window.οnscrοll=antiShake(function(){
console.log("我顶你个非啊")
},100)
function antiShake(func,delay){
var timer=null
return function(){
clearInterval(timer);
timer= setTimeout(function(){
func();
},delay)
}
};
//函数的节流
window.οnscrοll=throttle(function(){
console.log("我顶你个肺");
});
function throttle(func){
var d=new Date();
var firstTime=d.getTime();
return function(){
// console.log("11111");
var now=new Date().getTime();
if(now-firstTime>500){
func();
firstTime=now;
}
}
}
</script>