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>
  • 相关阅读:
    随机ID添加
    学生ID查询
    node.js基础
    冒泡排序
    循环判断语句
    vue.js详细教程--优优优
    final注意事项
    HashMap Hashtable区别
    java中间件
    JSP错误页面
  • 原文地址:https://www.cnblogs.com/plBlog/p/15268331.html
Copyright © 2011-2022 走看看