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.

[ 213 ]<br />

Chapter 8<br />

In the previous screenshot, we can see that the proximity container is resized and the<br />

scroller element is centered within it. We can also see the default message at the bottom<br />

<strong>of</strong> the proximity container.<br />

Time for action – animating the scroller<br />

The next section <strong>of</strong> code deals with actually animating the scroller element based on where<br />

the mouse pointer is relative to the outer proximity container:<br />

function goAnim(e) {<br />

var <strong>of</strong>fset = prox.<strong>of</strong>fset(),<br />

resetOffset = e.pageX - <strong>of</strong>fset.left - middle,<br />

}<br />

normalizedDuration = (resetOffset > 0) ? resetOffset :<br />

-resetOffset,<br />

duration = (middle - normalizedDuration) * 50;<br />

scroller.stop().animate({<br />

left: (resetOffset < 0) ? 0 : "-" + (parseInt(scroller.width())<br />

- parseInt(prox.width()))<br />

}, duration, "linear");

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

Saved successfully!

Ooh no, something went wrong!