Please enable JavaScript.
Coggle requires JavaScript to display documents.
Handling Events (Key events (event.keyCode :
get number in KeyboardEvent…
Handling Events
Key events
-
-
-
-
shiftkey, ctrlKey, altKey, metaKey: event property keyboard and mouse
keypress: only for keys that produce character input
use : string,formCharCode function to turn this code
ex: console.log(String.fromCharCode(event.charCode));
Propagation
a button in a paragraph is clicked, event handles on the paragraph will also receive the click event
but if the both botton have a handler , the more specific handler - the one on the button : get to go first
when you click paragraph outside , don't affect
button inside it
-
-
Mouse clicks
-
click : contain both the press and release the buttonpgaeX, and pageY: relative to top -left corner of the document
clientX and clientY : the same pageX àd pageYbut relative the part of the document that is currently scrolled into view
-
-
Events and DOM nodes
-
Catch event each element
example:
var button = document.querySelector("button");
button.addEventListener("click", function() {
console.log("Button clicked.");
});
-
-
-
-
-
-
Debouncing
If you do need to do something nontrivial in such a handler, you can use setTimeout to make sure you are not doing it too often.
-