<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,body{
height: 500%;
}
</style>
</head>
<body>
<button id="btn">歌谣</button>
<script>
function throwttle(fn,dalay){
var timer=null;
return function(){
clearTimeout(timer);
timer= setTimeout(function(){
fn.apply(this);
},dalay)
}
}
document.getElementById('btn').onclick=throwttle(function(){console.log('scroll事件被触发了'+Date.now())},200)
</script>
</body>
</html>
运行结果