Skip to content

Instantly share code, notes, and snippets.

@almog
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almog/c1d8f26247e6a4a924d2 to your computer and use it in GitHub Desktop.
Save almog/c1d8f26247e6a4a924d2 to your computer and use it in GitHub Desktop.

Chapter 14 - Events

  • MouseEvent which property tells us which button was clicked (1 - left, 2 - middle, 3 - right).
  • Events in JS propagate outward only, is that true? Isn't there a inward propagation before that (like in good old Flash)?
  • What's the difference between stopPropagation and stopImmediatePropagation?
  • Is there a way to know if an event's default action was cancelled? Is there a way to un-cancel it?
  • "keydown" event is trigerred everytime the key repeats itself.
  • String.prototype.charCodeAt does what you think it does.
  • Keybord Events have shiftKey, ctrlKey, altKey, and metaKey flags.
  • "keypress" is fired after "keydown" but is only fired for keys that generate text-input.
  • String.fromCharCode translates a code into a charcter.
  • Most nodes cannot be targets to key events, unless they're given a tabindex attribute.
  • The "click" event's target is the most immediate parent of the preceding 'mousedown' and 'mouseup' events.
  • Clicks events' coordinates can be obtained from the event's pageX and pageY.
  • mouse events' clientY viewPort's Y coordinate while the pageY is the document's Y coordinate.
  • getBoundingClientRect too, by default, returns the viewports coordinates
  • Given a circle bound inside a box, when the mouse moves from the box to the circle, a 'mouseout' event whose target is the box is triggered o_O
  • Mouse events have a relatedTarget property which, for the 'mouseout' event hold the value of the element the user preferred over us :(
  • You can't prevent past events from happening, scroll events is one of them.
  • load/focus/blur events do not propagate. Is there a good reason for that?
  • Script tags are executed as soon as they're encountered.
  • innerWidth/Height hold the window's viewport dimensions.
  • outerWidth/Height (which were not mentioned in the book) hold the window's dimensions.
  • "The scrollHeight value is equal to the minimum clientHeight the element would require in order to fit all the content in the viewpoint without using a vertical scrollbar" -mdn
  • Unload example from MDN: window.addEventListener("beforeunload", function( event ) { event.returnValue = "\o/"; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment