开发者

How to trigger only if it match 2 events in Jquery?

I want to have a event th开发者_如何学编程at only triggers when you press space and move your mouse at the same time. How can you make that?


You could make one event that sets a variable to true when space is pressed down, and to false when it is released. Then you can check that variable in your mouseclick event.

Using closure, you can put this in your document ready function. This will work when clicking on the DOM with id "container"

(function () {
   var space = false;
   $("document").keyup(function(e) {
     if (e.keyCode == 32) {
       space = false;
     }
   }).keydown(function(e) {
     if (e.keyCode == 32) {
       space = true;
     }
   });
  $("#container").click(function() {
    if (space) {
      // Do action
    }
  });
})();


Duplicasion

Check if the spacebar is being pressed and the mouse is moving at the same time with jQuery?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜