Vyoms OneStopTesting.com - Testing EBooks, Tutorials, Articles, Jobs, Training Institutes etc.
OneStopGate.com - Gate EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopMBA.com - MBA EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopIAS.com - IAS EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopSAP.com - SAP EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopGRE.com - of GRE EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
Bookmark and Share Rss Feeds

Fading, Hiding and Sliding HTML Elements with the GX JavaScript Animation Framework | Articles | Recent Articles | News Article | Interesting Articles | Technology Articles | Articles On Education | Articles On Corporate | Company Articles | College Articles | Articles on Recession
Sponsored Ads
Hot Jobs
Fresher Jobs
Experienced Jobs
Government Jobs
Walkin Jobs
Placement Section
Company Profiles
Interview Questions
Placement Papers
Resources @ VYOMS
Companies In India
Consultants In India
Colleges In India
Exams In India
Latest Results
Notifications In India
Call Centers In India
Training Institutes In India
Job Communities In India
Courses In India
Jobs by Keyskills
Jobs by Functional Areas
Learn @ VYOMS
GATE Preparation
GRE Preparation
GMAT Preparation
IAS Preparation
SAP Preparation
Testing Preparation
MBA Preparation
News @ VYOMS
Freshers News
Job Articles
Latest News
India News Network
Interview Ebook
Get 30,000+ Interview Questions & Answers in an eBook.
Interview Success Kit - Get Success in Job Interviews
  • 30,000+ Interview Questions
  • Most Questions Answered
  • 5 FREE Bonuses
  • Free Upgrades

VYOMS TOP EMPLOYERS

Wipro Technologies
Tata Consultancy Services
Accenture
IBM
Satyam
Genpact
Cognizant Technologies

Home » Articles » Fading, Hiding and Sliding HTML Elements with the GX JavaScript Animation Framework

Fading, Hiding and Sliding HTML Elements with the GX JavaScript Animation Framework








Article Posted On Date : Monday, April 5, 2010


Fading, Hiding and Sliding HTML Elements with the GX JavaScript Animation Framework
Advertisements

In this penultimate part of the series, I introduce you to using some extra methods provided by the GX library that come in useful for performing various operations. These include fading in and fading out, slides, and even manipulating the visibility of web page elements. All of these animation tasks can be accomplished very easily.

Creating engaging animations on your web pages does not always imply that you have to put your pockets (or your credit card) under strain buying expensive software like Flash or Swift 3D. Thanks to the generosity of many developers worldwide, you can pick up a JavaScript framework for free among the numerous ones available on the web, and start turning your divs, paragraphs and lists into dynamic elements.

In reality, at present there's such a great variety of animation frameworks available that choosing one that fits your needs without overkill can be a challenging task. Fortunately, making the right decision doesn't have to be a painful experience. This is especially true if you're a big fan of jQuery; you may want to try GX, a powerful plug-in that will let you implement all sorts of eye-catching effects on your (X)HTML documents without having to mess up a single portion of your clean markup.

Naturally, if you've been a loyal follower of this article series and have already read all of the tutorials previous to this one, you now have a strong background in how to use the GX library for creating different types of effects, ranging from altering the dimensions of an HTML element and varying its opacity, to moving it up and down across the browser.

While it's fair to stress that in most cases these effects were performed via the workhorse of GX, that is its handy "gx()" method, the library comes with a few additional, convenient methods that can be used for animations such as fade-ins and fade-outs, slides and even hiding elements entirely. Therefore, if you're interested in learning how to put these methods to work for you, in this penultimate part of the series I'll be taking a close look at them.

Let's start exploring the functionality of these fine animation methods.


As I just expressed in the introduction, the GX library is capable of performing smooth transitions in the opacity of web page elements through a complementary set of specific methods, not surprisingly called "fadeIn()" and "fadeout()." In consonance with the library's flat learning curve, working with these methods is a fairly straightforward process. The code fragment below demonstrates this in a nutshell. 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">

// use the fadeOut/fadeIn effects

$(document).ready(function(){

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

$('#container').fadeOut(2000).fadeIn(2000)

});

});

</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 the fadeOut()/fadeIn() effects</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>

In this concrete example, the aforementioned "fadeIn()" and "fadeout()" methods have been chained to produce a simple effect where the opacity of the target div is first reduced to 0 (zero) and them restored to its initial value. Nothing stops you, though, from using the methods separately or even in the reverse order, especially if you need to make a specific element vanish gracefully from display.

In addition to the earlier code sample, here's a simple diagram that shows how the pertinent fade-in/fade-out sequence is performed on the target div:

I don't want to sound over-excited, but since using the previous methods should be a breeze even for an inexperienced designer, it's time to explore two more methods bundled with the GX library. Therefore, in the following section I'll be showing how to slide an HTML element easily via two new methods, called "slideIn()" and "slideOut()."

To learn more about this topic, click on the link below and keep reading.


Another interesting facet of the GX library worth looking at is its ability to slide HTML elements in and out, which can be achieved via an additional set of methods, called "slideIn()" and "slideOut()" respectively. In the GX library's jargon, the term "sliding" is used to implement an effect where the height of the target element is altered in some form, thus the sequential invocation of the previous methods would cause the element to be alternately expanded and contracted.

That's exactly what the following code snippet attempts to demonstrate. Check it out:

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

// use the slideOut/slideIn effects

$(document).ready(function(){

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

$('#container').slideOut(1000).slideIn(1000)

});

});

</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 the slideOut()/slideIn() effects</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 I just said, calling the "slideIn()" and "slideOut()" methods in a predefined sequence will make the selected element alternately reduce or enlarge its height. Similar to the fade-in/fade-out example shown in the previous segment, the sliding methods have been chained, but naturally it's possible to use them separately or in the sequence that best suits your needs.

A diagram should help you to understand more easily how the sliding-in/sliding-out process works, so below I included one for you. Here it is:

Well, assuming that you've now grasped the logic behind working with the "slideIn()" and "slideOut()" methods, I'd like to spend a few moments exploring another handy pair of complementary methods offered by GX. These permit you to hide and display an HTML element in a snap. Not surprisingly, these methods are called "hide()" and "show()," and in the last section of this tutorial I'll be showing you how to work with them at a basic level.

Now, jump ahead and read the next few lines.


Certainly, one the most common effects that can be seen today on many web pages is the programmatic manipulation of the visibility of several HTML elements. As one might expect, GX also comes with a couple of methods, called "hide()" and "show()," that makes this process simple.

To illustrate how to use these simple methods, here's another trivial example that alternates calling each one. Take a look at it:

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

// use the hide/show effects

$(document).ready(function(){

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

$('#container').hide(1000, 'Elastic').show(1000, 'Elastic')

});

});

</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 the hide()/show() effects</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>

True to form, the above code fragment is self-explanatory. It simply hides and shows, in sequence, a target div. Again, it's valid to point out that the methods can be invoked individually, so keep this in mind when implementing this type of hide/show effect on your own web pages.

And with this last example, we've come to the end of this tutorial. As always, feel free to edit all of the code snippets shown previously, so you can arm yourself with a better grounding in using these fine methods that come with the GX framework.

Final thoughts

Over this penultimate chapter of the series, I introduced you to using some extra methods provided by the GX library. As you saw for yourself a moment ago, they come in useful for performing fade-ins/fade-outs, slides and even manipulating the visibility of web page elements.

Nevertheless, the list of these methods doesn't stop here. GX comes with a few more that can be used for scaling and moving HTML elements on screen. Thus, the final installment of the series will cover the use of these additional methods, concluding our overview of this powerful animation library.






Sponsored Ads



Interview Questions
HR Interview Questions
Testing Interview Questions
SAP Interview Questions
Business Intelligence Interview Questions
Call Center Interview Questions

Databases

Clipper Interview Questions
DBA Interview Questions
Firebird Interview Questions
Hierarchical Interview Questions
Informix Interview Questions
Microsoft Access Interview Questions
MS SqlServer Interview Questions
MYSQL Interview Questions
Network Interview Questions
Object Relational Interview Questions
PL/SQL Interview Questions
PostgreSQL Interview Questions
Progress Interview Questions
Relational Interview Questions
SQL Interview Questions
SQL Server Interview Questions
Stored Procedures Interview Questions
Sybase Interview Questions
Teradata Interview Questions

Microsof Technologies

.Net Database Interview Questions
.Net Deployement Interview Questions
ADO.NET Interview Questions
ADO.NET 2.0 Interview Questions
Architecture Interview Questions
ASP Interview Questions
ASP.NET Interview Questions
ASP.NET 2.0 Interview Questions
C# Interview Questions
Csharp Interview Questions
DataGrid Interview Questions
DotNet Interview Questions
Microsoft Basics Interview Questions
Microsoft.NET Interview Questions
Microsoft.NET 2.0 Interview Questions
Share Point Interview Questions
Silverlight Interview Questions
VB.NET Interview Questions
VC++ Interview Questions
Visual Basic Interview Questions

Java / J2EE

Applet Interview Questions
Core Java Interview Questions
Eclipse Interview Questions
EJB Interview Questions
Hibernate Interview Questions
J2ME Interview Questions
J2SE Interview Questions
Java Interview Questions
Java Beans Interview Questions
Java Patterns Interview Questions
Java Security Interview Questions
Java Swing Interview Questions
JBOSS Interview Questions
JDBC Interview Questions
JMS Interview Questions
JSF Interview Questions
JSP Interview Questions
RMI Interview Questions
Servlet Interview Questions
Socket Programming Interview Questions
Springs Interview Questions
Struts Interview Questions
Web Sphere Interview Questions

Programming Languages

C Interview Questions
C++ Interview Questions
CGI Interview Questions
Delphi Interview Questions
Fortran Interview Questions
ILU Interview Questions
LISP Interview Questions
Pascal Interview Questions
Perl Interview Questions
PHP Interview Questions
Ruby Interview Questions
Signature Interview Questions
UML Interview Questions
VBA Interview Questions
Windows Interview Questions
Mainframe Interview Questions


Copyright © 2001-2025 Vyoms.com. All Rights Reserved. Home | About Us | Advertise With Vyoms.com | Jobs | Contact Us | Feedback | Link to Us | Privacy Policy | Terms & Conditions
Placement Papers | Get Your Free Website | IAS Preparation | C++ Interview Questions | C Interview Questions | Report a Bug | Romantic Shayari | CAT 2025

Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |


Copyright ©2001-2025 Vyoms.com, All Rights Reserved.
Disclaimer: VYOMS.com has taken all reasonable steps to ensure that information on this site is authentic. Applicants are advised to research bonafides of advertisers independently. VYOMS.com shall not have any responsibility in this regard.