js节流
<html>
<head>
    <style>
        .box{width: 200px;height: 200px;background: #0a76a4}
    </style>
</head>
   <body>
   <h2>js节流</h2>
   <div class="box"></div>
    <script>
        let box=document.querySelector(".box")
        box.addEventListener("touchmove",throttle(demo,1000))
        function throttle(event,time) {
            let timer=null
            return function(){
                if(!timer){
                    timer=setTimeout(()=>{
                        event()
                        timer=null
                    },time)
                }
            }
        }
        function demo(){
            console.log("发起请求")
        }
    </script>
   </body>
</html>



复制内容


评论


乖,登录后才可以留言! 登录

Copyright © 2020-2023 春藤技术,春藤建站 All Rights Reserved
备案号:豫ICP备20020705号 公网安备 51LA统计