//为了解决用户重复操作DOM的问题;
// 函数防抖
function decounce(func,wait){
var timer;//初始化定时器;
return function(){
var content = this;
var args= arguments;
clearTimeout(timer);//每次执行先清除定时器;
timer = setTimeout(function(){
func.apply(content,args)
},wait)
}
}
//函数节流;解决用户频繁触发DOM的方法,使用时间戳;
function throttle(func, wait) {
var prv = 0;
var timer = null;
return function () {
var context = this;
clearTimeout(timer);
var arg = arguments;
var now = +new Date();
if (now - prv >= wait) {
func.apply(context, arg);
prv = now;
}
else {
timer = setTimeout(function () {
func.apply(context, arg);
}, wait);
}
}
}