JQuery undoing a large number of events

I am writing a program with two keyboard modes, using jquery.hotkeys.js , I see a slowdown and blinking when canceling all closing events. Is there a better way to do this?

function bindAll() { //bind all keystroke events $(document).bind('keydown','a', function(evt) { //... } $(document).bind('keydown','b', function(evt) { //... } //etc... } function unbindAll() { $(document).unbind('keydown'); return true; } //end unbinding all keystrokes 
+4
source share
1 answer

jQuery offers you the ability to create namespaces for events. It looks like this:

 $(document).bind('keydown.mySpace', function(evt) { }); $(document).bind('keyup.mySpace', function(evt) { }); // etc. 

You can .unbind() all the events that have been added to the namespace, for example:

 $(document).unbind('.mySpace'); 

I do not know about the plugin that you talked about, but you should study the documents or even better the source. If it is well designed, you should be able to use jQuery event namespaces for this purpose.

+5
source

Source: https://habr.com/ru/post/1339854/