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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Canvas <strong>Animation</strong>s<br />

Time for action – making our code compatible with IE<br />

In this example we will recreate our flag example so that it works as intended in IE.<br />

1. Resave the canvas.html page as canvas-explorer.html and add a reference<br />

to the explorercanvas library in the <strong>of</strong> the page:<br />

<br />

2. Now change the script at the bottom so that it appears like this (new/changed code<br />

is shown in bold):<br />

var canvas = document.getElementById("c"),<br />

draw = function(context) {<br />

context.fillStyle = "#039";<br />

context.fillRect(50, 50, 400, 200);<br />

context.beginPath();<br />

context.strokeStyle = "#fff";<br />

context.lineWidth = 50;<br />

context.moveTo(250, 50);<br />

context.lineTo(250, 250);<br />

context.moveTo(50, 150);<br />

context.lineTo(450, 150);<br />

context.moveTo(50, 50);<br />

context.lineTo(450, 250);<br />

context.moveTo(50, 250);<br />

context.lineTo(450, 50);<br />

context.stroke();<br />

context.closePath();<br />

context.strokeStyle = "#C00";<br />

context.lineWidth = 30;<br />

context.beginPath();<br />

context.moveTo(250, 50);<br />

context.lineTo(250, 250);<br />

context.moveTo(50, 150);<br />

context.lineTo(450, 150);<br />

context.stroke();<br />

context.lineWidth = 1;<br />

context.fillStyle = "#C00";<br />

[ 278 ]

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

Saved successfully!

Ooh no, something went wrong!