节流
var app = document.getElementById("app")
function addone() {
console.log("我是结束后出现的内容")
}
function shake(func,times) {
let time;
return function () {
if (!time) {
time = setInterval(function () {
func()
clearInterval(time)
time = null
}, times)
} else {
console.log("已经有定时器了",2000)
}
}
}
app.addEventListener("click", shake(addone))
防抖
var app = document.getElementById("app")
function addone() {
console.log("我是结束后出现的内容")
}
function shake(func) {
let time;
return function () {
clearInterval(time)
time = setInterval(function () {
func()
}, 1000)
}
}
app.addEventListener("click", shake(addone))