<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
<script>
window.addEventListener('resize',function(){
console.log('change')
})
function debounce(func,wait){
var timeId = null;
return function(){
//此处巧妙,实现了用户频繁输入,减少执行核心代码次数的功能
clearTimeout(timeId)
timeId = setTimeout(function(){
func()
},wait||200)
}
}
window.addEventListener('resize',debounce(function(a,b,c){
console.log('change')
},3000))
</script>
极简实现js去抖动,用于优化频繁操作.
最新推荐文章于 2023-02-25 15:26:34 发布