Throttle event calls in jQuery

前端 未结 7 874
自闭症患者
自闭症患者 2020-11-27 03:52

I have a keyup event bound to a function that takes about a quarter of a second to complete.

$(\"#search\").keyup(function() {
  //code that tak         


        
7条回答
  •  死守一世寂寞
    2020-11-27 04:04

    I came across this question reviewing changes to zurb-foundation. They've added their own method for debounce and throttling. It looks like it might be the same as the jquery-debounce @josh3736 mentioned in his answer.

    From their website:

    // Debounced button click handler
    $('.button').on('click', Foundation.utils.debounce(function(e){
      // Handle Click
    }, 300, true));
    
    // Throttled resize function
    $(document).on('resize', Foundation.utils.throttle(function(e){
      // Do responsive stuff
    }, 300));
    

提交回复
热议问题