JavaScript Events Flashcards

1
Q

What is the event for clicking on a button?

A

click

button.addEventListener(‘click’, cb);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the event for losing focus?

A

blur

canvas.addEventListener(‘blur’, cb);

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the event for gaining focus?

A

focus

canvas.addEventListener(‘focus’, cb);

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the event for starting a ‘touch’?

A

touchstart

canvas.addEventListener(‘touchstart’, callback);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the event for ending a touch?

A

touchend

canvas.addEventListener(‘touchend’, callback);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the event for detecting a touch has moved?

A

touchmove

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly