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

The previous screenshot shows the blind in its fully-open state. [ 157 ] Chapter 6 What just happened? We set a click handler on the outer container which calls the toggle() method on the inner element. In the CSS we set the inner element to be hidden initially, so the first time the container element is clicked, the inner element will be shown. The clip effect The clip effect causes the element it is called upon to reduce in size vertically or horizontally until it disappears. Configuration options The configuration options we have at our disposal when using the clip effect allow us to control the direction in which the animation proceeds, and whether the element is shown or hidden: Option Default Usage direction "vertical" Sets the axis along which the element animates. mode "hide" Configures whether the element is hidden or shown. Other possible values are show, toggle, and effect.

Extended Animations with jQuery UI Time for action – clipping an element in and out This effect is billed as being similar to what happens to the picture when an old television set is turned off, so let's work that into our example. 1. Add the following elements to the of the template file: 2. Then use the following simple script at the bottom of the page: $("#tv").click(function() { $("#static").effect("clip"); }); 3. Save this file as clip.html. The stylesheet for this example is as follows: #tv { width:300px; height:269px; position:relative; cursor:pointer; background:url(../img/tv.png) no-repeat 0 0; } #bg { width:220px; height:180px; position:absolute; left:42px; top:30px; z-index:-2; background-color:#000; } #static { width:216px; height:178px; position:absolute; left:44px; top:31px; z-index:-1; background:url(../img/static.gif) no-repeat 0 0; } 4. Save this file in the css folder as clip.css. 5. When the page is run, we should be able to click anywhere on the television and see the effect run: [ 158 ]

Extended <strong>Animation</strong>s with <strong>jQuery</strong> UI<br />

Time for action – clipping an element in and out<br />

This effect is billed as being similar to what happens to the picture when an old television set<br />

is turned <strong>of</strong>f, so let's work that into our example.<br />

1. Add the following elements to the <strong>of</strong> the template file:<br />

<br />

<br />

<br />

<br />

2. Then use the following simple script at the bottom <strong>of</strong> the page:<br />

$("#tv").click(function() {<br />

$("#static").effect("clip");<br />

});<br />

3. Save this file as clip.html. The stylesheet for this example is as follows:<br />

#tv {<br />

width:300px; height:269px; position:relative; cursor:pointer;<br />

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

}<br />

#bg {<br />

width:220px; height:180px; position:absolute; left:42px;<br />

top:30px;<br />

z-index:-2; background-color:#000;<br />

}<br />

#static {<br />

width:216px; height:178px; position:absolute; left:44px;<br />

top:31px;<br />

z-index:-1; background:url(../img/static.gif) no-repeat 0 0;<br />

}<br />

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

5. When the page is run, we should be able to click anywhere on the television and see<br />

the effect run:<br />

[ 158 ]

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

Saved successfully!

Ooh no, something went wrong!