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>

  • 相关阅读:
    windows常规
    oracle常规操作
    idea使用
    java-maven
    java-rabbimq
    centos7 rabbitMq 安装教程
    Leetcode 332.重新安排行程
    Leetcode 334.递增的三元子序列
    Leetcode 331.验证二叉树的前序序列化
    Leetcode 330.按要求补齐数组
  • 原文地址:https://www.cnblogs.com/shangjun6/p/10600472.html
Copyright © 2011-2022 走看看