You are on page 1of 2

setTimeout(changeScene, 10000);

setInterval(drawAvatar, 1000);
eventlisteners
gameCanvas.addEventListener("mousemove", redrawAvatar);
redrawAvatar(mouseEvent)
document.getElementById("myBtn").addEventListener("click", displayDate);
Syntax :
element.addEventListener(event, function, useCapture);
removeEventListener()
element.removeEventListener("mousemove", myFunction);

events :
mouseout
mousemove
click
keypress
keydown

var canvas = document.getElementById("canvas_1");


canvas.addEventListener("touchstart", doTouchStart, false);
The touch event is more complex to capture than the mouse event. The first line
of code is this:
event.preventDefault();
The default behaviour for touch events is a continuous monitoring of touches, sc
rolls and gestures. We only want it to detect one touch so are preventing the de
fault behaviour.
Touches are stored in an array called targetTouches. The first of these can be u
sed to get the X and Y coordinates of the touch:
canvas_x = event.targetTouches[0].pageX;
canvas_y = event.targetTouches[0].pageY;

If you want the entire browser window to accept a key press event, the code woul
d be this:

window.addEventListener( "keypress", doKeyDown, false )


<input type="text" onkeydown="myFunction()">

You might also like