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.

context.closePath();<br />

pos.ne.x = pos.ne.x - 2;<br />

pos.ne.y = pos.ne.y - 1;<br />

pos.se.x = pos.se.x - 2;<br />

pos.se.y = pos.se.y + 1;<br />

pos.nw.x = pos.nw.x + 2;<br />

pos.nw.y = pos.nw.y + 1;<br />

pos.sw.x = pos.sw.x + 2;<br />

pos.sw.y = pos.sw.y - 1;<br />

} else {<br />

clearInterval(crossInt);<br />

redCross(context);<br />

}<br />

},<br />

growVertical = function() {<br />

if (height < 200 || width < 400) {<br />

if (height < 200) {<br />

height = height + 2;<br />

context.fillRect(225, 50, 50, height);<br />

}<br />

if (width < 400) {<br />

width = width + 4;<br />

context.fillRect(50, 125, width, 50);<br />

}<br />

} else {<br />

clearInterval(rectInt);<br />

crossInt = setInterval(function() { growDiagonal() }, 1);<br />

}<br />

},<br />

rectInt = setInterval(function() { growVertical() }, 1);<br />

},<br />

[ 285 ]<br />

Chapter 10<br />

What just happened?<br />

Essentially we have another inline function, which contains another function that gets<br />

repeatedly called with another interval. As we're drawing white crosses this time, we need to<br />

set some style properties (we'll be drawing both lines and rectangles in this function and so<br />

set the fillStyle and strokeStyle) as well as the lineWidth property.<br />

We initialize width and height control variables, which will be used to control how many<br />

times the interval runs, and we also store the starting positions <strong>of</strong> the vertical and diagonal<br />

crosses in an object called pos.

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

Saved successfully!

Ooh no, something went wrong!