Home arrow JavaScript arrow Page 2 - Making Bouncing Effects in Parallel with the GX JavaScript Animation Framework
JAVASCRIPT

Making Bouncing Effects in Parallel with the GX JavaScript Animation Framework


In this fourth installment of a series, I provide you with some friendly examples that show how to use the GX library for creating an appealing bouncing effect when performing parallel animations on a target div. The process is extremely simple, so you shouldn’t have major trouble if you need to implement this kind of effect on your own web pages.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
January 26, 2010
TABLE OF CONTENTS:
  1. · Making Bouncing Effects in Parallel with the GX JavaScript Animation Framework
  2. · Review: bouncing HTML elements with the GX library
  3. · More effects: using a Bounce easing for parallel animations
  4. · A more sophisticated bouncing animation

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Making Bouncing Effects in Parallel with the GX JavaScript Animation Framework - Review: bouncing HTML elements with the GX library
(Page 2 of 4 )

Just in case you haven’t read the previous article, where I discussed how to use the GX library to add a bouncing effect when animating a simple div, in the lines to come I reintroduced a couple of the examples I developed then. The first of these makes the target div bounce when its width is modified, and the corresponding source code looks like this:

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

// use bounce easing to change the width of the targeted div element

$(document).ready(function(){

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

        $('#container').gx({'width': 600}, 3000, 'Bounce');

    });

});

</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>Using bounce easing to change the width of the targeted div 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>

That was easy to code and read, wasn’t it? As seen above, implementing a bouncing effect when performing a simple animation is only a matter of passing a value of “Bounce” to the “gx()” method and nothing else. In this particular case, the property being changed was the div’s width, but as you may guess, it’s feasible to achieve a similar result when modifying a different property. That’s exactly what the following example does. 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">

// use bounce easing to change the height of the targeted div element

$(document).ready(function(){

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

        $('#container').gx({'height': 300}, 3000, 'Bounce');

    });

});

</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>Using bounce easing to change the width of the targeted div 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>

Definitely, the code of the previous example speaks for itself, so I’m not going to waste your valuable time explaining its inner workings. However, it’s valid to point out an interesting thing about the way that it implements the bouncing effect. As you can see, it performs the animation on just a single property of the target div, which is nice, but it would be desirable to produce a similar result when animating multiple properties as well.

Well, as I anticipated in the introduction, the GX library permits us to do this in a truly simple fashion. So, in the course of the following section I’ll be showing you how to make a div bounce when altering simultaneously its width and height.

To learn the complete details of this process, read the segment to come. It’s only one click away.


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