Introduction
Before reading this article, please go through the following articles:
- Part 1: jQuery UI Demystified: Part 1
- Part 2: jQuery UI Demystified: Part 2
In this article, we will learn about jQuery effects.The following effects will be covered.
- Add Class
- Color Animation
- Effect
- Hide
- Remove Class
- Show
- Switch Class
- Toggle
- Toggle Class
In my Part 1 article we learned how to add a jQuery Widget on a HTML element. In Part 2 we learned how to add jQuery Interactions on HTML elements. Now in this part, we will complete this jQuery Demystified series. jQuery effects are very important for making a good website design. It gives your site a smooth transition and a pleasant appeal. So what are we waiting for? Let's Dive In!
Quick Synopsis of Part 2
In Part 2 we cover the jQuery interactions. We covered the following effects:

Let's move ahead now on jQuery effects.
Preparing the workspace
- Add the following code in your new HTML to make it ready for the rest of the article.
- <html>
- <head>
- <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
- <meta charset="utf-8" />
- <title>jQuery Demystified Part 3</title>
- <style>
- /* we will use this section for adding css classes */
- </style>
- </head>
- <body>
- <script>
- $(document).ready(function () {
- // We will use this for adding our jQuery
- });
- </script>
- </body>
- </html>
Working with jQuery Effects
Add Class
- Add this peice of code in the html section:
- <div class='addcls'></div>
-
Add these two classes in your style section:
- .addcls{
- width:50px;
- height:20px;
- background-color:orange;
- }
- .addclsOP{
- width:300px;
- height:80px;
- background-color:blue;
- }
Here 'addcls' is the default class and we will change it to 'addclsOP'. -
Add this in your script section:
- $(document).ready(function () {
- $(".addcls").click(function () {
- $(this).addClass("addclsOP", 1000, "easeOutBounce");
- });
- });
Here we add the "addclsOP" in the div when the user clicks on it. This changes the property of the element on which the click is performed. ".addClass" has syntax like this:
".addClass("class_to_add",duration,other_options)".
Remove Class
-
Append this in your HTML section:
- <div class="addclsOP addcls"></div>
This div has two classes "addclsOP" and "addcls". We'll remove the addclsOP on the click of the user on the second div. -
Append this code to your script section:
- $( ".addclsOP" ).click(function() {
- $( this ).removeClass( "addclsOP", 3000, "easeOutBounce" );
Here the class addclsOP is removed from the div when the user clicks on that div. The general syntax of ".removeClass" is
".removeClass("class_to_remove",duration,other_options)".

Animate
-
Append this in your HTML section:
- <div class='clrAnim'>Color Animation</div>
This div will be used to animate its color and size when the user clicks on it. -
Append this class in your style section:
- .clrAnim{
- width:300px;
- height:80px;
- background-color:pink;
- }
This is the default class on the div and its content will be changed using the ".animate" method. -
Now append this script in your script section:
- $(".clrAnim").click(function () {
- $(this).animate({
- color: "white",
- backgroundColor: "black",
- height: "160px"
- }, 1000);
- });
The syntax for ".animate" is: ".animates("options_to_animate",duration,other_options)".







Join the conversation! Your thoughts help the community grow.