Home arrow JavaScript arrow Page 4 - Manipulating Background Colors with the GX JavaScript Animation Framework
JAVASCRIPT

Manipulating Background Colors with the GX JavaScript Animation Framework


In this second installment of a series, I take a deeper look at a few more features provided by the GX library. Specifically, I show how to use them for performing parallel animations that include changing the width, height and background color of a sample div.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
January 21, 2010
TABLE OF CONTENTS:
  1. · Manipulating Background Colors with the GX JavaScript Animation Framework
  2. · Review: basic animations with the GX framework
  3. · Modifying the background color of a sample div
  4. · Manipulating the background color and height of a div simultaneously

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Manipulating Background Colors with the GX JavaScript Animation Framework - Manipulating the background color and height of a div simultaneously
(Page 4 of 4 )

In the previous section, I coded an example that illustrated how to manipulate at the same time the width and the background color of a simple div. Now, let me show you an example that will perform the same parallel animation, but altering the height of the div. Here’s how this brand new example looks:


<!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">

// change the height and background color of the targeted div element

$(document).ready(function(){

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

$('#container').gx({'height': 300, 'background-color': '#ff8040'}, 1000, 'Linear');

});

});

</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>Click on the div below to change its height and background color</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>


As you can see, a small modification in a parameter passed to the handy “gx()” method produces an animation that is drastically different. In this case, when the animation is triggered after the web page has finished loading, the selected div smoothly changes its background color along with its height. To understand more accurately how this process works, pay attention to the following figure:



There you have it. Once more, this shows how easy it is to perform more complex animations with the GX library. As usual, I suggest that you edit all the code samples developed in this article, so you can start implementing your own animation effects on web pages. The experience will be truly educational, believe me.

Final thoughts

That’s all for now. In this second installment of the series, I took a deeper look at a few more features provided by the GX library and showed how to use them for performing parallel animations that included changing the width, height and background color of a sample div. In all the examples, the “gx()” method did the hard work, so I suggest you have fun passing other values to this method and see what happens in each case.

In addition, you may have noticed that all of the animations shown so far used a “Linear” value for the easing argument. Well, while this is handy, the GX library permits you to create bouncing and elastic effects by tweaking this argument.

That’s exactly the topic that I’ll be discussing in the next tutorial. Thus, now that you know what to expect from that part of the series, you can’t miss it!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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