Debounce function in Jquery?

前端 未结 2 1096
攒了一身酷
攒了一身酷 2021-01-25 15:06

Been looking for a debounce function or way to debounce in Jquery. The build up of animations can get super annoying. Heres the code:

function fade() {
    $(\         


        
2条回答
  •  面向向阳花
    2021-01-25 15:25

    I don´t like the idea to include a library just for a debounce function. You can just do:

    var debounce = null;
    $('#input').on('keyup', function(e){
       clearTimeout(debounce );
       debounce = setTimeout(function(){
          $.ajax({url: 'someurl.jsp', data: {query: q}, type: 'GET'})
       }, 100);
    });
    

提交回复
热议问题