RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
js 防抖与节流

1. 概念上的区别(从 handle 的有效性分析)

  1. 防抖:多次执行只有最后一次生效,必要参数 [ handle, time ]
  2. 节流:一段时间内只能执行一次,必要参数 [ handle, time ]

2. 实现一下

  1. 防抖:
     1 function debounce(handle, time) {
     2     let timer = null;
     3     return function () {
     4         if (timer) {
     5             clearTimeout(timer);
     6             timer = null;
     7         }
     8         timer = setTimeout(() => {
     9             handle();
    10         }, time);
    11     };
    12 }

    标题名称:js 防抖与节流
    文章地址:http://scyingshan.cn/article/dsojicc.html