目录
防抖
简单理解防抖的内容:对当前操作重复执行会造成不必要的性能浪费,通过防抖可以让自定义时长内的重复操作的前n次都不执行,只执行最后一次,我们以一个简单mouseover事件举例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#test{
width: 200px;
height: 200px;
margin: 0 auto;
background-color: antiquewhite;
text-align: center;
line-height: 200px;
}
</style>
</head>
<body>
<div id="test">
</div>
<script type="text/javascript">
const test =document.querySelector('#test')
function pass(e){
this.innerHTML=(e.screenX+','+e.screenY)
}
test.addEventListener('mousemove',pass)
</script>
</body>
</html>
鼠标在div内移动时会实时生成坐标展示在dom元素里