JavaScript Events Flashcards Preview

Web Technologies > JavaScript Events > Flashcards

Flashcards in JavaScript Events Deck (10)
Loading flashcards...
1
Q

What is the event for clicking on a button?

A

click

button.addEventListener(‘click’, cb);

2
Q

What is the event for losing focus?

A

blur

canvas.addEventListener(‘blur’, cb);

(on the window it’s - onblur)
window.onblur

3
Q

What is the event for gaining focus?

A

focus

canvas.addEventListener(‘focus’, cb);

(on the window it’s - onfocu)
window.onfocus

4
Q

Which events do you use to pause a game - if the tabs or changed or the browser is no longer the main app?

A

blur / focus

5
Q

What event do you use to determine where the mouse is on screen?

A

mousemove

You can do this on the canvas. NOTE: it returns screen coords - so make sure you subtract the mouse coordinates from the canvas coords.

var rect = canvas.getBoundingClientRect();
mousex = evt.x - rect.left;
mousey = evt.y - rect.top;
6
Q

What is the event for starting a ‘touch’?

A

touchstart

canvas.addEventListener(‘touchstart’, callback);

7
Q

What is the event for ending a touch?

A

touchend

canvas.addEventListener(‘touchend’, callback);

8
Q

How would you prevent a user from dragging the canvas?

A

In the touchstart event handler - make sure you call:

evt.preventDefault

(NOTE: This probably isn’t an issue in something like Intel XDK)

9
Q

What is the event for detecting a touch has moved?

A

touchmove

10
Q

How would you prevent users from double tapping, to zoom into the canvas?

A

have a evt.preventDefault call in the touchend event