> 文章列表 > 节流throttle

节流throttle

节流throttle


document.getElementById(“rightSvgTemplate”).onmousemove = throttle(function(e){
showBox(e)
}, 1000);

showBox(){
//处理逻辑
}

export function throttle(fn,wait){
console.log(wait,‘、、、、’)
var pre = Date.now();
return function(){
var context = this;
var args = arguments;
var now = Date.now();
console.log(wait,now , pre,now - pre)
if( now - pre >= wait){
console.log(‘/??’)

      fn.apply(context,args);pre = Date.now();}

}
}