Home arrow JavaScript arrow Page 2 - Using the jQuery Library`s Animation Effects
JAVASCRIPT

Using the jQuery Library`s Animation Effects


Welcome to the conclusion of an eight-part series that introduces the jQuery JavaScript library. This versatile library lets you build robust client-side applications very rapidly, thanks in part to an extremely friendly programming interface. In this article, you'll learn how to use the library to build some excellent animation effects.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
September 30, 2009
TABLE OF CONTENTS:
  1. · Using the jQuery Library`s Animation Effects
  2. · The slideUp() and slideDown() animation
  3. · The slideToggle() and fadeIn() methods
  4. · Developing customized animations with jQuery's animate() method

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the jQuery Library`s Animation Effects - The slideUp() and slideDown() animation
(Page 2 of 4 )

As I mentioned in the introduction, the jQuery framework comes with methods which can be used specifically to animate, at a basic level, certain elements of a web document with relative ease.

The first two animation methods that I'm going to show you in this tutorial are the ones called "slideUp()" and "slideDown()" respectively. As their names suggest, these methods will apply a slide effect to any targeted web page element. In the first case, that is when using the "slideUp()" method, the element will be progressively hidden by reducing its height, while when utilizing "slideDown()," the element will be displayed by increasing it.

Now that I've explained how these two methods function, please look at the following pair of code samples, which show them in action. Here they are:

(example of using "slideUp()" method)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Basic example on using jQuery with slideUp() method</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

font: 24px bold Arial, Helvetica, sans-serif;

color:#000;

}

div{

width: 200px;

padding: 10px;

background: #ffc;

}

</style>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$("a").click(function(){

$("div").slideUp("slow");

return false;

});

});

</script>

</head>

<body>

<h1>Basic example on using jQuery with slideUp() method</h1>

<a href="#">Click to hide the DIV...</a>

<div>

Content of the DIV goes here... Content of the DIV goes here... Content of the DIV goes here... Content of the DIV goes here...

</div>

</body>

</html>

(example of using "slideDown()" method)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Basic example on using jQuery with slideDown() method</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

font: 24px bold Arial, Helvetica, sans-serif;

color:#000;

}

div{

width: 200px;

padding: 10px;

background: #ffc;

display: none;

}

</style>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$("a").click(function(){

$("div").slideDown("slow");

return false;

});

});

</script>

</head>

<body>

<h1>Basic example on using jQuery with slideDown() method</h1>

<a href="#">Click to show a DIV...</a>

<div>

Content of the DIV goes here... Content of the DIV goes here... Content of the DIV goes here... Content of the DIV goes here...

</div>

</body>

</html>

As I explained earlier, if you test the code samples listed above on your own browser, then you'll see that the DIV included in the two previous web documents will be displayed and hidden alternately, in accordance with the kind of effect applied to it. Even though these hands-on examples are pretty simple, they should be good enough to demonstrate the animation capabilities offered by the "jQuery" package.

Okay, at this point, you hopefully learned how to use the "slideUp()" and "slideDown()" methods discussed previously, so what comes next? Well, in the next section, I'm going to teach you how to use two additional animation methods, named "slideToggle()" and "fadeIn()," to turn the visibility of a selected web page element on and off by using a sliding effect and a fade-in transition.

To learn the full details of how these methods will be put to work, please click on the link below and keep reading.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials