/**
* 节流函数
*/
var count = 1;
var container = document.getElementById('container');
function getUserAction(e) {
// console.log(this)
// console.log(e);
container.innerHTML = count++;
}
function throttle(func, wait) {
var context, args;
var timeout;
var previout = 0;
return function() {
context = this;
args = arguments; // 可以拿到事件处理函数的 enent对象
if(!timeout) {
timeout = setTimeout( () => {
timeout = null;
func.apply(context, args)
}, wait)
}
}
}
container.onmousemove = throttle(getUserAction, 2000, true);