I want to have a event that only triggers when you press space and move your mouse at the same time. How can you make that?
A:
Anurag
2010-03-30 08:44:25
+1
A:
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
}
});
})();
googletorp
2010-03-30 08:44:45
It works, thanks! There is one problem. The page goes down when i press space. I tried to use e.preventDefault(); , but then it prevent whole document. I dont want it to prevent in for example input-tags
Codler
2010-03-30 09:31:00