The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 3


Code Explanation


} Close clause


if (nbally < inboxboundy) { Is the y value less than the top boundary?


nbally = inboxboundy; If so, set the y value to be exactly the boundary


ballvy = -ballvy; Change the vertical displacement


} Close clause


ballx = nballx; Set the x position to nballx


bally = nbally; Set the y position to nbally


} Close moveandcheck function


function change() { Start of change function


ballvx = Number(f.hv.value); Convert input to number and assign to ballvx


ballvy = Number(f.vv.value); Convert input to number and assign to ballvy


return false; Returnfalse to make sure there isn't a page reload


} Close function


Close script
Close head
Start body element. Set up call to init function

<canvas id="canvas" width=
"400" height="300">


Start of canvas element

Your browser doesn't support the
HTML5 element canvas.


Message for non-compliant browsers

Close canvas element


Line break

Free download pdf