• 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>

  • 相关阅读:
    jpa和postgres实现保存json格式数据
    Linux系统编程03动态库
    Linux系统编程04Makefile
    Linux系统编程09stat和lstat
    Linux系统编程01GCC
    Linux系统编程07read和write
    Linux系统编程05GDB调试
    Linux系统编程08lseek.md
    C++面向对象构造函数与析构函数
    Linux系统编程06open
  • 原文地址:https://www.cnblogs.com/shangjun6/p/10600472.html
Copyright © 2020-2023  润新知