1.4 - Events in Detail Flashcards
Mouse events can be splitted into 2 categories, simple and complex, it is right?
YES
Mouse events can be split into how many categories? and who are them
2 categories
simple and complex
Describe some of the most used simple mouse envents
mousedown / mouseup
mouseover / mouseout
mousemove
Some of the most used mouse simple events are:
mousedown / mouseup
mouseover / mouseout
mousemove
YES
mousedown / mouseup
Describe it
In what category is it?
description: mouse button is clicked / released over an element
category: simple
mouseover / mouseout
Describe it
In what category is it?
description: mouse pointer comes over / out from an element
category: simple
mousemove
Describe it
In what category is it?
describe: every mouse move over an elemen triggers that event
category: simple
some of the most used complex mouse events are
click
contextmenu
dblclick
?
yes
some of the most used complex events are?
click
contextmenu
dblclick
complex events are made of simple ones?
yes
Complex events are made of …?
simple ones
click event
Describe it
In what category is it?
description: triggers after mousedown and then mouseup is released over the same element
category: complex
contextmenu event
Describe it
In what category is it?
description: triggers after mousedown if the right mouse button was used
category: complex
dblclick
Describe it
In what category is it?
description: triggers after a double click over an element.
category: complex
Can an action trigger multiple events?
explain it with an example
YES
a click first triggers mousedown, when the button is pressed, then mouseup and click when it’s released
How is the events order in the case when a single action initiates multiple events?
describe the click event
Their order is fixed.
The handlers are called in the order
mousedown -> mouseup -> click
A click first triggers mousedown, when the buttos is pressed, then mouseup and click when it’s released
The which property is:
allows to get the mouse button ?
YES
What is the usage or purpose of the which property on click-related events?
Click related events always have the which property that allows to get the button
The which property it’s used for click and contextmenu events?
No, because those happens only on left click and on right click only
When it is usefull the which property on click related events?
When we are tracking mousedown and mouseup, because these events trigger on any button, so which allows to distinguish between “right-mousedown” and “left-mousedown”
Name the possible values of the which property
All mouse events include the information about pressed modifier keys?
YES
Can we know about any modifier key being pressed, when using mouse events?
and why?
YES
because all mouse events include the information about pressed modifier keys
What are the modifiers keys?
shiftKey
altKey
ctrlKey
metaKey (cmd for mac)
All mouse events have coordinates in 2 flavours
who are them?
window-relative: clientX and clientY
document-relative: pageX and pageY
When clicking on text what side-effect may be disturbing?
That a double click selects the text
If we want to handle click events ourselves, then the “extra” selection doesn´t look good.
Why mouseove/mouseout and mouseenter/mouseleave are special, what do they have?
the have a relatedTarget
In mouseover
what it means
event.target
event.relatedTarget
event.target - is the element where the mouse came over
event.relatedTarget - is the element from which the mouse came
In mouseout
what it this:
event.target
event.relatedTarget
?
event.target - is the element that mouse left
event.relatedTarget - is the new under-the-pointer element (that mouse left for)
relatedTarget can have a value of null?
YES
When and what it means that, relatedTarget can have a value of null?
It’s normal and just means that the mouse came not from another element, but from out of the window. Or that it left the window.
Keep that possibility in mind wen using event.relatedTarget. If we access event.relatedTarget.tagName, then there will be an error.
How can we explain this situation?
According to the browser logic, when using mouseover/mouseout the mouse cursor may be only over a single element at any time - the most nested one (and top by z-index).
So if it goes to another element (even a descendant) then it leaves the previous one. That simple!
What are the differences between
mouseenter/mouseleave and mouseover/mouseout
?
1 - Transitions inside the element are not counted.
2 - Events mouseenter / mouseleave do not bubble
What could be a problem when using mouseenter/mouseleave?
That they don´t bubble.
So we can´t use the event delegation pattern on them.
Who are the events that trigger even when we go from the parent element to a child element? and why?
mouseover / mouseout
They assume that the mouse can be only over one element at one time - the deepest one.
Who are the events that don´t bubble?
mouseenter / mouseleave do not bubble
Who are the events that only track whether the mouse comes inside and outside the element as a whole?
mouseenter / mouseleave
Who are the events that do not trigger when the mouse goes to a child element?
mouseenter / mouseleave
Who are the events that have an additional target: relatedTarget ?
mouseover / mouseout
mouseenter / mouseleave
Who are the events that assume that the omuse can be only over one element at one time - the deepest one?
mouseover / mouseout
What is the difference between mousemove, mouseenter and mouseover
The mouseover event triggers when the mouse pointer enters the div element, and its child elements.
The mouseenter event is only triggered when the mouse pointer enters the div element.
The mousemove event triggers every time the mouse pointer is moved over the div element.
When listening for the event mousemove, it means that:
every pixel leads to an event?
Explain the answer with an example
NO
The browser checks the mouse position from time to time. And if he notices changes then triggers the events.
That means that if the visitor is moving the mouse very fast then DOM-elements may be skipped:
it is true that
clientX/Y coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window
yes
It is true that
pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),
yes
Tanto pageX/Y como clientX/Y
Son´numeros?
Si son números, que representan coordenadas
Tanto pageX/Y como clientX/Y sabemos que son números, pero que representan esos números?
Son coordenadas
Tanto pageX/Y como clientX/Y son números, que representan coordenadas, en relación a qué?
pageX/Y: sus coordenadas son en relación a la esquina superior izquierda de toda la página renderizada(inclusive las partes ocultas por hacer scroll)
clientX/Y: sus coordenadas son en relación a la esquina superior izquierda en relación a la viewport( la parte actualmente visible en el navegador )
complete:
……. …. coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),
pagex / y
Complete:
………. …. coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window
clientX / Y
What is the viewport in HTML
Is the part of the webpage that the user can currently see. The scrollbars move the viewport to show other parts of the page
Y para evitar cualquier confusión, no es ni el tamaño de la ventana(window) del navegador, ni la resolución de pantalla. Dos ventanas con el mismo tamaño, pero un navegador con más barras de herramientas mostradas tendrá una ventana de visualización más pequeña
What is the difference between, clientX/Y and pageX/Y?
pageX, pageY, screenX, screenY, clientX and clientY returns a number which indicates the number of physical “css pixels” a point is from the reference point
The event point is where the user clicked, the reference point is a point in the upper left
pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling)
clientX/Y coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window
Describe pagex/pageY
pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),
Describe clientx/y
clientX/Y coordinates are relative to the top left corner of the visible part of the page, “seen” through browser window
Describe the image
pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),
while clientX/Y coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window.
pageX, pageY, screenX, screenY, clientX, clientY
it is true that returns a number wich indicates the number of physical “css pixels” a point is from the reference point?
yes
pageX, pageY, screenX, screenY, clientX, clientY
it is true that returns a number wich indicates?
the number of physical “css pixels” a point is from the reference point?
If we want to track any input into an < input > field, keyboard events are enough?
NO, they are not enough
When keydown and keyup events happens?
keydown happens when a key is pressed down
keyup happens when a key is pressed up
It is true to say that:
the event.key property allows to get the character
and
the event.code property get the “physical key code”
YES
How can we get a character
with event.key
How can we get the code of a character?
like “KeyX”
with event.code
Suppose a user works with different language, then switching language would make a totally different character if he press Z character.
How will change, key or code
event.code will be always the same “KeyZ”
Every key has the …. that depends on its location on the keyboard?
Complete the word
every has the code…
Name the key codes for
Letters
Digits
key: KeyA, KeyB, etc…
Digit: Digit0, Digit1, etc…
Name the key codes for special keys like:
Enter or backspace or the tab
Enter
Backspace
Tab
When working with event.code, case matters?
YES
The first letter of “Key” must be upppercase
Witch one is responsible for telling us exactly which key was pressed?
event.code tells us exactly which one was presed, and event.key is responsible for the “meaning” of the key: what is a “shift”
When a key is being pressed for a long enough time, it starts to ?
repeat, keydown triggers again and again
For all repeating keys the event object has what with what value?
the event object has the event.return property set to true.
Which key never generates a keyboard event
The Fn key, there is no keyboard event for it