02.06.2013 Views

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<br />

Your browser doesn't support the canvas element!<br />

<br />

<br />

<br />

(function($) {<br />

})(<strong>jQuery</strong>);<br />

<br />

<br />

<br />

[ 291 ]<br />

Chapter 10<br />

2. Save the file as canvas-game.html. We also require a very basic stylesheet for<br />

our game. All we're styling is the element itself. Create a new stylesheet<br />

containing the following style rules:<br />

canvas {<br />

border:1px solid #000; margin:auto; display:block;<br />

outline:none;<br />

background:url(../img/bg.gif) no-repeat;<br />

}<br />

3. Save this file in the css directory as canvas-game.css.<br />

What just happened?<br />

The main element on the page is <strong>of</strong> course the element. The only difference<br />

between this and the element used in previous examples is that we have set the tabindex<br />

attribute on it so that it can receive keyboard events, which is necessary for detecting and<br />

reacting to the input from the user. We're also using <strong>jQuery</strong> in this example and using the<br />

standard anonymous function + $ aliasing construct we've used throughout the book.<br />

The styles we've used simply position the element in the center <strong>of</strong> the page, give<br />

it a border, and remove the dotted outline that appears around focused elements in some<br />

browsers. We also set a background image on the element.<br />

The background image applied to the element helps to set a scene for our game,<br />

and using CSS to set a background image on the element is much easier than<br />

drawing the image within it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!