• js多次触发事件,在一定延迟内只执行一次 (事件累加)


      js多次触发事件,在一定延迟内只执行一次的案例:

        <!DOCTYPE html>
        <html>
          <head>
            <meta charset="UTF-8">
            <title></title>
            <style>
              .div{
                200px;
                height:200px;
                background:red;
                transition:width 2s linear 0s;
              }
            </style>
          </head>
          <body>
            <div class="div"></div>
          </body>
        </html>
        <script>
          var div=document.querySelectorAll(".div")[0];
          var num=0;
          var t=null;
          //事件累加的功能
          //js 多次触发点击事件,在一定延迟内只执行一次
          div.onclick=function(){
            if(t!=null){
              clearTimeout(t)
            }
            t=setTimeout(function(){
              num++;
              console.log(num);
            },500)
          }

        </script>

  • 相关阅读:
    Qt状态机实例
    <STL> accumulate 与 自定义数据类型
    <STL> 容器混合使用
    散列表(C版)
    Canonical 要将 Qt 应用带入 Ubuntu
    <STL> set随笔
    C++ 文件流
    视频播放的基本原理
    <STL> pair随笔
    c++ 内存存储 解决char*p, char p[]的问题
  • 原文地址:https://www.cnblogs.com/shangjun6/p/10600472.html
Copyright © 2020-2023  润新知