Home arrow JavaScript arrow Page 2 - Toggling CSS Properties with the GX JavaScript Animation Framework
JAVASCRIPT

Toggling CSS Properties with the GX JavaScript Animation Framework


In this ninth episode of the series, I provide you with some comprehensive examples that show how to toggle different properties of a sample div by using the core “gx()” method of the GX library. As with many tasks the GX JavaScript animation framework can be made to perform, toggling animations is a very simple process.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
February 09, 2010
TABLE OF CONTENTS:
  1. · Toggling CSS Properties with the GX JavaScript Animation Framework
  2. · Toggling the width of a div in a single step
  3. · Dynamically expanding and contracting an HTML element
  4. · Toggling the opacity of an HTML element

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Toggling CSS Properties with the GX JavaScript Animation Framework - Toggling the width of a div in a single step
(Page 2 of 4 )

As with many other effects that can be implemented with the GX library, toggling a specified property of an HTML element is usually carried out via its core “gx()” method. However, this type of animation is even simpler to create than the regular kind, as the whole process is reduced to passing the string “toggle” to the method, preceded by the name of the property that needs to be manipulated. That’s all.

To illustrate how to perform an animation like this, below I included a basic example. It will toggle the value assigned to the “width” CSS property of a div when clicking on this element. Take a look at it, please:

<!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=utf-8" />

<title>Using the GX Animation Library</title>

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

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

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

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

<script type="text/javascript">

// toggle the width of the targeted div element

$(document).ready(function(){

$('#container').click(function(){

$('#container').gx({width: 'toggle'})

});

});

</script>

<style type="text/css">

body {

padding: 0;

margin: 0;

background: #fff;

font: 1em Arial, Helvetica, sans-serif;

color: #000;

}

#wrapper {

width: 960px;

margin: 0 auto;

}

#header, #content, #footer {

padding: 30px;

}

#container {

width: 300px;

padding: 10px;

background: #ffffc0;

border: 1px solid #000;

}

</style>

</head>

<body>

<div id="wrapper">

<div id="header">

<h1>Using the GX Animation Library</h1>

<h2>Header section</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

</div>

<div id="content">

<h2>Toggling the width of the targeted element</h2>

<div id="container">

<p>This container will be animated via the GX animation library. For more information on GX, please click <a href="http://gx.riccardodegni.net/">here</a>.</p>

</div>

</div>

<div id="footer">

<h2>Footer section</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

</div>

</div>

</body>

</html>

Well, you’ll have to agree with me that understanding how the above code sample functions isn’t rocket science, right? As I said before, the whole toggling process is performed via the handy “gx()” method, which in this case is used for modifying the width of the target div.

In addition to the code snippet that you just saw, here’s a complementary image that schematically represents the previous toggling animation:

So far, so good. Having already demonstrated how easy it is to toggle the width of a simple div via the “toggle” argument, it’s time to explore other possible implementations of this effect. Thus, in the course of the following section I’ll be tweaking the earlier example for toggling the value assigned to the div’s “height” property.

Now, to see how the new example will be developed, click on the link below and read the segment to come.


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 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials