<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>函数防抖</title>
</head>
<body>
<div id="layout" style="height: 100px; width: 100px; background-color: mistyrose"></div>
<script>
var node = document.getElementById('layout')
let count=0;
function getUserAction(e) {
console.log(this,e+":"+count)
node.innerHTML = ++count;
};
node.onmousemove = debounceRe(getUserAction,3000)
function debounce(func,waitTime) {
var timer
return function () {
var context = this;
var args = arguments;
clearTimeout(timer)
timer = setTimeout(function () {
func.apply(context,args)
},waitTime)
}
}
</script>
</body>
</html>