<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>节流</title>
</head>
<body>
<input type="text" placeholder="鼠标反复经过我">
</body>
<script>
// 节流主要运用于快速点击,鼠标滑动,鼠标滚轮滚动,下拉加载发请求等
let timer = null
let input = document.querySelector('input')
input.addEventListener('mouseover', function () {
if (timer != null) {
return
}
timer = setTimeout(() => {
console.log("节流")
timer = null
}, 500)
})
</script>
</html>
标签:触发,节流,timer,let,事件,input,null
From: https://www.cnblogs.com/orangeczs/p/17034672.html