jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of

02.06.2013 Views

ackground:url(../img/dock.png) no-repeat 0 0; } .icon { position:absolute; top:-15px; left:44px; } .icon img { border:none; } #mail { left:108px; } #safari { left:170px; } #firefox { left:229px; } #itunes { left:289px; } 4. Save this file as size.css in the css folder. 5. When we run the file in a browser, we should see that the individual items in the menu grow and shrink as the mouse pointer moves over them: [ 151 ] Chapter 6 In the previous screenshot we see the menu as the pointer hovers over one of the items in the menu. What just happened? We attach mouseenter and mouseleave event handlers to each item within the dock using jQuery's hover() method, which accepts two functions, the first being executed on the mouseenter event, the second being executed on mouseleave. In the first function we use the stop() method to manage the queue and then animate the element's position by changing its top CSS value. Using stop() here prevents an unsightly jarring of the element's position on screen. We then navigate down the image inside the link and call the stop() method on this element too before applying the size effect. We provide integer values for the width and height keys in a configuration object and as these values are larger than the dimensions of the image, the image will be increased in size.

Extended Animations with jQuery UI Note that when we use the stop() method with the image, it is to prevent a build-up of effects if the mouse pointer is repeatedly moved on and off one of the links. The second function is really the reverse of the first function, which simply resizes the element back to its original position and size. The transfer effect The transfer effect simply transfers the outline of one element to another element. Like the size effect that we looked at a moment ago, the transfer effect will not work if it is not configured. Configuration options The transfer effect has only two configuration options, although only one is mandatory. These options are listed in the following table: Option Default Usage className none The value of this option, if set, is added to the transfer element when the effect runs to none A jQuery selector that specifies the target element that the transfer element is sent to Time for action – transferring the outline of one element to another In this example we'll recreate a popular application installation dialog from OSX, and use the transfer effect to help show visitors where to drag the icon (the icon won't actually be draggable, all we're doing is looking at the transfer effect). 1. Add the following elements to the of the template file to create the install dialog: To install the application, drag its icon over to the apps folder icon. Show me [ 152 ]

ackground:url(../img/dock.png) no-repeat 0 0;<br />

}<br />

.icon { position:absolute; top:-15px; left:44px; }<br />

.icon img { border:none; }<br />

#mail { left:108px; }<br />

#safari { left:170px; }<br />

#firefox { left:229px; }<br />

#itunes { left:289px; }<br />

4. Save this file as size.css in the css folder.<br />

5. When we run the file in a browser, we should see that the individual items in the<br />

menu grow and shrink as the mouse pointer moves over them:<br />

[ 151 ]<br />

Chapter 6<br />

In the previous screenshot we see the menu as the pointer hovers over one <strong>of</strong> the items in<br />

the menu.<br />

What just happened?<br />

We attach mouseenter and mouseleave event handlers to each item within the dock using<br />

<strong>jQuery</strong>'s hover() method, which accepts two functions, the first being executed on the<br />

mouseenter event, the second being executed on mouseleave.<br />

In the first function we use the stop() method to manage the queue and then animate the<br />

element's position by changing its top CSS value. Using stop() here prevents an unsightly<br />

jarring <strong>of</strong> the element's position on screen.<br />

We then navigate down the image inside the link and call the stop() method on this<br />

element too before applying the size effect. We provide integer values for the width and<br />

height keys in a configuration object and as these values are larger than the dimensions <strong>of</strong><br />

the image, the image will be increased in size.

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

Saved successfully!

Ooh no, something went wrong!