var timer = null
function debounce(fn,time){
//触发频率小于500ms是则清除上次未执行的
clearTimeout(time)
setTimeout(function(){
console.log('====执行=====')
fn()
},time)
}
//监听搜索input change事件
element.addEventListener("input", function(event) {
debounce(searchFunc,500)
})
//搜索
searchFunc(){
console.log('====serch=====')
}
var startTime = 0
function throttle(fn,time){
let nowTime = (new Date()).valueOf()
if(nowTime-startTime > time){
fn()
startTime = nowTime
}
}
document.addEventListener("mousemove",function(){
//每隔1秒执行一次drag
throttle(drag(),1000)
});
function drag(){
console.log('=====执行=====')
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |