zoukankan      html  css  js  c++  java
  • js防抖函数

    <script>
      function debounce (fn, delay) {//防抖
        let timer = null;
        let firstTime = false;
        return function (...args) {
          let context = this;
          if (firstTime) {
            // 第一次加载
            fn.apply(context, args);
            return firstTime = false;
          }
          console.log(timer)
          if (timer) {
            // 定时器正在执行中,跳过
            return;
          }
          timer = setTimeout(() => {
            clearTimeout(timer);
            timer = null;
            fn.apply(context, args);
          },  delay);
          console.log(timer)
        };
      }
      var doms = document.getElementById('demo')
      doms.addEventListener('click', debounce(loctionthrottleFn, 1000))
      function loctionthrottleFn () {
        let _this =this
        console.log(123)
      }
    </script>

    <body>
    <div id="app"></div>
    <div id="demo">惦记我</div>
    </body>
  • 相关阅读:
    何为 ISAPI
    MacDown-The open source Markdown editor for OS X.
    Atom使用
    运维
    Perl
    Kaggle
    J2EE
    leetcode
    Tensorflow 学习笔记
    EXCEL公式及宏
  • 原文地址:https://www.cnblogs.com/plBlog/p/15268331.html
Copyright © 2011-2022 走看看