zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    stompjs使用
    WKWebView新窗口打开链接
    iOS实现自定义拍照页面
    Universal Link
    社群app开发问题记录
    C#中try catch finally
    如何生成代码项目的工程结构
    C# SqlSugar基于 .NET 开源ORM框架
    C# DataGridView 行和列的操作
    禁止EditText 自动弹出软键盘
  • 原文地址:https://www.cnblogs.com/shangjun6/p/10600472.html
Copyright © 2011-2022 走看看