dom节流与去抖

 

节流:throttle,用于input keyup

getValue:function(){
  var principalVal=$('#principal').val();
  console.log(principalVal)
},

throttle(that.getValue, null, 500, this.value);

function throttle(fn,context,delay,text){
  clearTimeout(fn.timeoutId);
  fn.timeoutId = setTimeout(function(){
    fn.call(context,text);
  },delay);
}

  • throttle 等时间间隔执行函数。
  • debounce 时间间隔 t 内若再次触发事件,则重新计时,直到停止时间大于或等于 t 才执行函数。

 

posted @ 2018-09-10 16:38  xiaoyaoyaozheng  阅读(210)  评论(0编辑  收藏  举报