Why the keyup event is not fired on an element in JavaScript while moving the mouse with the left button held down? -
i guess came across pretty strange (to me) situation. have "keyup" event bound div (with tabindex
set, of course) contains google map. need disable map dragging functionality when shiftkey
pressed down , enable again when key goes up:
mapelement.setattribute("tabindex", 0); mapelement.focus(); google.maps.event.adddomlistener(mapelement, "mouseover", function(e) { mapelement.focus(); }); google.maps.event.adddomlistener(mapelement, "mouseout", function(e) { mapelement.blur(); }); google.maps.event.adddomlistener(mapelement, "keydown", function(e) { var isshift; if (window.event) { isshift = !!window.event.shiftkey; } else { isshift = !!e.shiftkey; } if (isshift) { map.setoptions({ draggable: false }); } });
now, in order add keyup
event, following:
google.maps.event.adddomlistener(mapelement, "keyup", function(e) { var isshift; console.log(e); if (window.event) { isshift = !!window.event.shiftkey; } else { isshift = !!e.shiftkey; } if (!isshift) { map.setoptions({ draggable: true }); } });
but event not fired if following steps in order:
1) press shift key down while mouse over map (mouseover
) (map dragging disabled here);
2) while holding down shift key, press left button of mouse , move cursor on map;
3) while moving cursor on map left button pressed, release shift key
(which held down time) -> here expect keyup
event set fired , map becomes draggable again, instead it's not...;
it works should if first release left mouse button and then raise shift
key up. of, course, workaround add "mousemove" event, this:
google.maps.event.adddomlistener(mapelement, "mousemove", function(e) { if (!e.shiftkey) { map.setoptions({ draggable: true }); } });
but more expert me in js event handling tell me what's going on here , why keyup
wasn't fired?
thanks attention!
Comments
Post a Comment