<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../css_com/reset.css">
<style>
.parent{
overflow: auto;
margin:10px auto;
width: 300px;
height: 300px;
border:1px solid red;
}
.child{
margin:0 auto;
width: 200px;
height: 2400px;
background-color: #56fff3;
}
</style>
<!--网络cdn提供jquery,自己下载好引用一样-->
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>
<body>
<!--<div class="parent" id="parent">-->
<!---->
<!--</div>-->
<div class="child" id="child"></div>
<script>
// 防抖
function debounce(fn, wait) {
var timeout = null;
return function() {
if(timeout !== null) clearTimeout(timeout);
timeout = setTimeout(fn, wait);
}
}
// 处理函数
function handle() {
console.log(Math.random());
}
// 滚动事件
window.addEventListener('scroll', debounce(handle, 1000));
</script>
</body>
</html>