zoukankan      html  css  js  c++  java
  • 防抖

    一、基本概念

    避免用户的频繁触发,将一定时间内的操作合并为一次,并在给定时间以后只执行一次

    二、实现

        function debounce1(fn,time){
            var timer = null
            return function(){
                clearTimeout(timer)
                timer = setTimeout(fn,time)
            }
        }
    

    用户的两次操作间隔小于time时,只执行最后一次 

    第一次点击触发操作

        function debounce2(fn,time){
            var timer = null
            return function(){
                clearTimeout(timer)
                if(timer){
                    timer = setTimeout(function(){
                        fn()
                    },time)
                } else {
                    fn()
                    timer = setTimeout(function(){
                        timer=null
                    },time)
                }
            }
        }
        
    

      

  • 相关阅读:
    asp.net读取/导入project(mpp)文件
    hdu2103
    hdu2100(大数加)
    hdu1406
    hdu1249
    hdu1038
    hdu2565
    hdu1203
    zoj3501
    hdu2102
  • 原文地址:https://www.cnblogs.com/lhyhappy365/p/10301102.html
Copyright © 2011-2022 走看看