input value changes, the delay trigger event

1.debounce to shake

function debounce(method,delay){
    var timer = null; 
    return function(){
        var context = this,args = arguments;
        clearTimeout(timer); 
        timer = setTimeout(function(){
            method.apply(context,args); 
        },delay);
    }
}

2.throttle throttle

function Throttle (Method, Delay, Time) {
      var timeout, the startTime + = new new a Date ();
      return  function () {
          var context = the this , 
         args = arguments, 
         curTime = + new new a Date (); 
         the clearTimeout (timeout); 
         // If the trigger reaches a predetermined time interval, triggers Handler 
         IF (curTime - the startTime> = time) { 
           method.apply (context, args); 
           the startTime = curTime; 
       } the else {
            //Does not reach the trigger interval, the timer is reset 
           timeout = the setTimeout (Method, Delay); 
     } 
 };

 

Guess you like

Origin www.cnblogs.com/ImmortalWang/p/11551159.html