<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<style>
body {
height: 300vh;
background-color: pink;
}
</style>
<script>
function debounce(func, delay) {
let timerId;
return function (...args) {
clearTimeout(timerId);
timerId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
const debouncedScrollHandler = debounce(function (event) {
console.log(event);
}, 200);
window.addEventListener("scroll", debouncedScrollHandler);
</script>
</html>