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>

  • 相关阅读:
    IOS开发之UIview
    poj2823(单调队列)
    poj3250(单调栈)
    poj2796(单调栈+树状数组)
    hdu5033(单调栈)
    hdu1506(单调栈)
    2018 Multi-University Training Contest 2
    hdu4417(主席树)
    2018 Multi-University Training Contest 1
    poj2104(主席树)
  • 原文地址:https://www.cnblogs.com/shangjun6/p/10600472.html
Copyright © 2011-2022 走看看