DOM Object Events Flashcards
AnimationEvent
an event for CSS animations
types: animationstart, animationend,
animationiteration (when an animation is repeated)
properties: animationName, elapsedTime,
psuedo-element
ClipboardEvent
Events that occur when the clipboard is modified
types: oncopy, oncut, onpaste
property: clipboardData
DragEvent
Events that occur when elements are dragged and/or dropped. Inherits properties from MouseEvent.
types: ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop
property: dataTransfer
FocusEvent
Events that occur when elements gets or loses focus. Inherits properties and methods from UiEvent.
types: onblur, onfocus
onfocusin (about to get focus)
onfocusout (about to lose focus)
InputEvent
Events that occur when a form element’s content changes. Inherits from UiEvent
type: oninput
properties: data, dataTransfer, getTargetRanges(), inputType, isComposing
TouchEvent, KeyboardEvent, MouseEvent properties:
altKey, ctrlKey, shiftKey, metaKey
Boolean properties that return true if each key was pressed when the event triggered
meta is command/windows key
KeyboardEvent
Events that occur when user presses a key on the keyboard. Inherits from UiEvent
types: onkeydown, onkeypress, onkeyup
properties: code, charCode, key, location, repeat, which
MouseEvent
Events that occur when the mouse interacts with the HTML document. Inherits from UiEvent
types: onclick, ondblclick, oncontextmenu (M2), onmousedown, onmouseenter, onmouseleave, onmousemove, onmouseout, onmouseover, onmousup
properties: clientX, clientY, screenX, screenY, movementX, movementY, offsetX, offsetY, pageX, pageY
client: browser
page: document
offset: target element
screen: user’s screen
movement: relative to prior mouse event
PageTransitionEvent
Events that occur when user navigates to, and away from, a webpage.
types: pagehide, pageshow
property: persisted (was the page cached by the browser)
ProgressEvent
Events that occur when loading external resources, belongs to the ProgressEvent Object.
types: onerror, onloadstart
TouchEvent
Events that occur when user touches a touch-based device
types: ontouchcancel, ontouchend, ontouchmove, ontouchstart
properties: touches, targettouches, changedtouches
TransitionEvent
Events that occur when a CSS transition runs
type: transitionend
properties: propertyName, elapsedTime, pseudoElement
UiEvent
Events that are triggered from the user interface.
Childrend of UiEvent: FocusEvent, InputEvent, KeyboardEvent, MouseEvent, TouchEvent, WheelEvent
types: abort, beforeunload, error, load, resize, scroll, select, unload
WheelEvent
Events that occur when the mouse wheel is scrolling. Inherits from MouseEvent and UiEvent
type: onwheel
properties: deltaX, deltaY, deltaZ, deltaMode
abort
when the loading of media is aborted
afterprint
an event that occurs when a page has started printing or if the print dialogue box has been closed
beforeprint
an event that occurs when a page is about to be printed
canplay
an event that occurs when a media has buffered enough to being
canplaythrough
The event occurs when the browser can play through the media without stopping for buffering
change
The event occurs when the content of a form element, the selection, or the checked state have changed (for input, select, and textarea)
ended
The event occurs when the media has reach the end (useful for messages like “thanks for listening”)
fullscreenchange
The event occurs when an element is displayed in fullscreen mode
message
The event occurs when a message is received through the event source
offline / online
The event occurs when the browser starts to work offline / online
pause, play, playing
events for when a media is paused of is no longer paused.
playing (resumed after pause)
submit
The event occurs when a form is submitted
What is Event Delegation?
The idea is that if we have a lot of elements handled in a similar way,
then instead of assigning a “handler” to each of them
We put a single handler on their common ancestor.
table.onclick = function(event) { let target = event.target; // where was the click?
if (target.tagName != ‘TD’) return; // not on TD? Then we’re not interested
highlight(target); // highlight it
};
How can event Delegation be used on a group of save load and search buttons?
div
button data-action=”save”>Save< /button
button data-action=”load”>Load< /button
button data-action=”search”>Search< /button
/div
class Menu { constructor(elem) { this._elem = elem; elem.onclick = this.onClick.bind(this); // (*) }
save() { alert('saving'); } load() { alert('loading'); } search() { alert('searching'); }
onClick(event) { let action = event.target.dataset.action; if (action) { this[action](); } }; } new Menu(menu);