Remove keydown delay in JavaScript?

前端 未结 3 962
花落未央
花落未央 2020-12-18 06:12

Well, when you hold a key on your keyboard, after the first fire there is a 1sec delay.
You can go ahead and open notepad and hold a key (e.x \'x\') you\'ll see after

3条回答
  •  一整个雨季
    2020-12-18 06:45

    you could start an event on keydown and stop it on keyup

    $('#mycanvas').on('keydown', function() { 
       $(document).trigger('start'); 
    }); 
    
    $('#mycanvas').on('keyup', function() { 
       $(document).trigger('stop'); 
    });
    
    $(document).on('start', startAnimation);
    $(document).on('stop', stopAnimation);
    
    function startAnimation(e) { //start something }
    function stopAnimation(e) { //stop something }
    

提交回复
热议问题