JQUERY - EFFECTSjQuery provides a trivially simple interface for doing various kind of amazing effects. jQuery methods allow us to quickly apply commonly used effects with a minimum configuration. This tutorial covers all the important jQuery methods to create visual effects. Showing and Hiding Elements The commands for showing and hiding elements are pretty much what we would expect: show() to show the elements in a wrapped set and hide() to hide them. Syntax Here is the simple syntax for show() method:
[selector].show( speed, [callback] );
Here is the description of all the parameters:
[selector].hide( speed, [callback] );
Here is the description of all the parameters:
Consider the following HTML file with a small JQuery coding:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show( 1000 ); }); $("#hide").click(function () { $(".mydiv").hide( 1000 ); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px;} </style> </head> <body> <div class="mydiv"> This is a SQUARE </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html> This will produce the following result
This is a SQUARE
Toggling the Elements jQuery provides methods to toggle the display state of elements between revealed or hidden. If the element is initially displayed, it will be hidden; if hidden, it will be shown. Syntax Here is the simple syntax for one of the toggle() methods:
[selector]..toggle([speed][, callback]);
Here is the description of all the parameters:
We can animate any element, such as a simple <div> containing an image:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $(".clickme").click(function(event){ $(".target").toggle('slow', function(){ $(".log").text('Transition Complete'); }); }); }); </script> <style> .clickme{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:50px;} </style> </head> <body> <div class="content"> <div class="clickme">Click Me</div> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </div> </body> </html> This will produce the following result
Click Me
![]() JQuery Effect Methods You have seen basic concept of jQuery Effects. Following table lists down all the important methods to create different kind of effects:
The animate( ) method performs a custom animation of a set of CSS properties. Syntax Here is the simple syntax to use this method:
selector.animate( params, [duration, easing, callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#out").click(function(){ $("#block").animate({ width: "70%", opacity: 0.4, marginLeft: "0.6in", fontSize: "3em", borderWidth: "10px" }, 1500 ); }); $("#in").click(function(){ $("#block").animate({ width: "100", opacity: 1.0, marginLeft: "0in", fontSize: "100%", borderWidth: "1px" }, 1500 ); }); }); </script> <style> div {background-color:#bca; width:100px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="out"> Animate Out </button> <button id="in"> Animate In</button> <div id="block">Hello</div> </body> </html> This will produce the following result: Click on any of the buttons Hello
fadeIn() Method The fadeIn( ) method fades in all matched elements by adjusting their opacity and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.fadeIn( speed, [callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#in").click(function(){ $(".target").fadeIn( 'slow', function(){ $(".log").text('Fade In Transition Complete'); }); }); $("#out").click(function(){ $(".target").fadeOut( 'slow', function(){ $(".log").text('Fade Out Transition Complete'); }); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="out"> Fade Out </button> <button id="in"> Fade In</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html> This will produce the following result: Click on any of the buttons ![]() fadeOut() Method The fadeOut( ) method fades out all matched elements by adjusting their opacity to 0, then setting display to "none" and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.fadeOut( speed, [callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#in").click(function(){ $(".target").fadeIn( 'slow', function(){ $(".log").text('Fade In Transition Complete'); }); }); $("#out").click(function(){ $(".target").fadeOut( 'slow', function(){ $(".log").text('Fade Out Transition Complete'); }); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="out"> Fade Out </button> <button id="in"> Fade In</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html> This will produce the following result: Click on any of the buttons ![]() fadeTo() Method The fadeTo( ) method fades the opacity of all matched elements to a specified opacity and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.fadeTo(speed, opacity[, callback]);
Parameters Here is the description of all the parameters used by thi method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#more").click(function(){ $(".target").fadeTo( 'slow', 0.7, function(){ $(".log").text('More Opacity Transition Complete'); }); }); $("#less").click(function(){ $(".target").fadeTo( 'slow', 0.2, function(){ $(".log").text('less Opacity Transition Complete'); }); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="less"> Less Opacity </button> <button id="more"> More Opacity</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html> Click on any of the buttons ![]() hide() Method The hide( ) method simply hides each of the set of matched elements if they are shown. There is another form of this method which controls the speed of the animation. Syntax Here is the simple syntax to use this method:
selector.hide( );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show(); }); $("#hide").click(function () { $(".mydiv").hide(); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px;} </style> </head> <body> <div class="mydiv"> This is a SQUARE. </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html>
This is a SQUARE.
hide( speed, [callback] ) Method The hide( speed, [callback] ) method hides all matched elements using a graceful animation and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.hide( speed, [callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show( 100 ); }); $("#hide").click(function () { $(".mydiv").hide( 100 ); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px;} </style> </head> <body> <div class="mydiv"> This is a SQUARE. </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html> This will produce the following result:
This is a SQUARE.
show() Method The show( ) method simply shows each of the set of matched elements if they are hidden. There is another form of this method which controls the speed of the animation. Syntax Here is the simple syntax to use this method:
selector.show( );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show(); }); $("#hide").click(function () { $(".mydiv").hide(); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px;} </style> </head> <body> <div class="mydiv"> This is a SQUARE. </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html> This will produce the following result:
This is a SQUARE.
show( speed, [callback] ) Method The show( speed, [callback] ) method shows all matched elements using a graceful animation and firing an optional callback after completion. Synta Here is the simple syntax to use this method −
selector.show( speed, [callback] );
Parameter Here is the description of all the parameters used by this method −
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show( 100 ); }); $("#hide").click(function () { $(".mydiv").hide( 100 ); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px;} </style> </head> <body> <div class="mydiv"> This is a SQUARE. </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html> This will produce the following result:
This is a SQUARE.
slideDown() Method The slideDown() method reveals all matched elements by adjusting their height and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.slideDown( speed, [callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show( 100 ); }); $("#hide").click(function () { $(".mydiv").hide( 100 ); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px;} </style> </head> <body> <div class="mydiv"> This is a SQUARE. </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html> This will produce the following result:
This is a SQUARE.
slideToggle() Method The slideToggle() method toggles the visibility of all matched elements by adjusting their height and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.slideToggle( speed, [callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#toggle").click(function(){ $(".target").slideToggle( 'slow', function(){ $(".log").text('Toggle Transition Complete'); }); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on the following button:</p> <button id="toggle"> Toggle </button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html> This will produce the following result: Click on the following button: ![]() slideUp() Method The slideUp() method hides all matched elements by adjusting their height and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.slideUp( speed, [callback] );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#down").click(function(){ $(".target").slideDown( 'slow', function(){ $(".log").text('Slide Down Transition Complete'); }); }); $("#up").click(function(){ $(".target").slideUp( 'slow', function(){ $(".log").text('Slide Up Transition Complete'); }); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="up"> Slide Up </button> <button id="down"> Slide Down</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html> This will produce the following result: Click on any of the buttons ![]() stop() Method The stop( [clearQueue, gotoEnd ]) method stops all the currently running animations on all the specified elements. Syntax Here is the simple syntax to use this method:
selector.stop( [clearQueue], [gotoEnd] ) ;
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#go").click(function(){ $(".target").animate({left: '+=100px'}, 2000); }); $("#stop").click(function(){ $(".target").stop(); }); $("#back").click(function(){ $(".target").animate({left: '-=100px'}, 2000); }); }); </script> <style> p {background-color:#bca; width:250px; border:1px solid green;} div{position: absolute; left: 50px; top:300px;} </style> </head> <body> <p>Click on any of the following buttons:</p> <button id="go"> GO</button> <button id="stop"> STOP </button> <button id="back"> BACK </button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click on any of the following buttons: ![]() toggle() Method The toggle() method toggles displaying each of the set of matched elements. Syntax Here is the simple syntax to use this method:
selector.toggle( );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#toggle").click(function(){ $(".target").toggle( ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on the following button:</p> <button id="toggle"> Toggle </button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click on the following button: ![]() toggle( speed, [callback]) Method The toggle( speed, [callback]) method toggles displaying each of the set of matched elements using a graceful animation and firing an optional callback after completion. Syntax Here is the simple syntax to use this method:
selector.toggle( speed, [callback]);
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#toggle").click(function(){ $(".target").toggle( 'slow', function(){ $(".log").text('Toggle Transition Complete'); }); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on the following button:</p> <button id="toggle"> Toggle </button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html> This will produce the following result: Click on the following button: ![]() toggle( switch ) Method The toggle( switch ) method toggle displaying each of the set of matched elements based upon the passed paratmer. If true parameter shows all elements, false hides all elements. Syntax Here is the simple syntax to use this method:
selector.toggle( switch );
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#false").click(function(){ $(".target").toggle(false); }); $("#true").click(function(){ $(".target").toggle(true); }); }); </script> <style> p {background-color:#bca; width:250px; border:1px solid green;} </style> </head> <body> <p>Click on any of the following buttons:</p> <button id="false"> False Switch </button> <button id="true"> True Switch </button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click on any of the following buttons: ![]() jQuery.fx.off() Method The jQuery.fx.off() method globally disables all the animations. Syntax Here is the simple syntax to use this method:
jQuery.fx.off = [true | false ] ;
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#enable").click(function(){ jQuery.fx.off = false; }); $("#disable").click(function(){ jQuery.fx.off = true; }); $("#go").click(function(){ $(".target").animate({left: '+=200px'}, 2000); }); $("#back").click(function(){ $(".target").animate({left: '-=200px'}, 200); }); }); </script> <style> p {background-color:#bca; width:350px; border:1px solid green;} div{position: absolute; left: 50px; top:300px;} </style> </head> <body> <p>Click enable or disable and then go or back button:</p> <button id="enable"> Enable</button> <button id="disable"> Disable </button> <button id="go"> GO</button> <button id="back"> BACK </button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click enable or disable and then go or back button: ![]() UI Library Based Effects To use these effects you can either download latest jQuery UI Library jquery-ui- 1.11.4.custom.zip from jQuery UI Library or use Google CDN to use it in the similar way as we have done for jQuery. We have used Google CDN for jQuery UI using the following code snippet in the HTML page so we can use jQuery UI –
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> </head>
The Blind effect can be used with show/hide/toggle. This blinds the element away or shows it by blinding it in. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "blind", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "blind", {direction: "horizontal"}, 1000 ); }); $("#show").click(function(){ $(".target").show( "blind", {direction: "horizontal"}, 1000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click on any of the buttons ![]() Bounce Effect The Bounce effect can be used with effect() method. This bounces the element multiple times, vertically or horizontally Syntax Here is the simple syntax to use this effect:
selector.effect( "bounce", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#button").click(function(){ $(".target").effect( "bounce", {times:3}, 300 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click the button</p> <button id="button"> Bounce </button> <div class="target"> </div> </body> </html> Click the button Clip Effect The Clip effect can be used with show/hide/toggle. This clips the element on or off, vertically or horizontally. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "clip", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "clip", {direction: "horizontal"}, 1000 ); }); $("#show").click(function(){ $(".target").show( "clip", {direction: "vertical"}, 1000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click on any of the buttons ![]() Drop Effect The Drop effect can be used with show/hide/toggle. This drops the element away or shows it by dropping it in. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "drop", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "drop", {direction: "up"}, 1000 ); }); $("#show").click(function(){ $(".target").show( "drop", {direction: "down"}, 1000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> <img src="./images/jquery.jpg" alt="jQuery" /> </div> </body> </html> This will produce the following result: Click on any of the buttons ![]() Explode Effect The Explode effect can be used with show/hide/toggle. This explodes or implodes the element into/from many pieces. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "explode", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "explode", {pieces: 16 }, 2000 ); }); $("#show").click(function(){ $(".target").show( "explode", {pieces: 16}, 2000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{width:100px; height:100px; background:red;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> </div> </body> </html> This will produce the following result: Click the button Fold Effect The Fold effect can be used with show/hide/toggle. This folds the element like a piece of paper. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "fold", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "fold", {horizFirst: true }, 2000 ); }); $("#show").click(function(){ $(".target").show( "fold", {horizFirst: true}, 2000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> </div> </body> </html> This will produce the following result: Click on any of the buttons Highlight Effect The Highlight effect can be used with effect() method. This highlights the element's background with a specific color, default is yellow. Syntax Here is the simple syntax to use this effect:
selector.effect( "highlight", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#button").click(function(){ $(".target").effect( "highlight", {color:"#669966"}, 3000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click the button</p> <button id="button"> Highlight </button> <div class="target"> </div> </body> </html> This will produce the following result: Click the button Puff Effect The Puff effect can be used with show/hide/toggle. This creates a puff effect by scaling the element up and hiding it at the same time. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "puff", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "puff", { }, 2000 ); }); $("#show").click(function(){ $(".target").show( "puff", {percent:100}, 2000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> </div> </body> </html> This will produce the following result: Click on any of the buttons Pulsate Effect The Pulsate effect can be used with effect() method. This pulsates the opacity of the element multiple times. Syntax Here is the simple syntax to use this effect:
selector.effect( "pulsate", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#button").click(function(){ $(".target").effect( "pulsate", {times:5}, 3000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click the button</p> <button id="button"> Pulsate </button> <div class="target"> </div> </body> </html> This will produce the following result: Click the button Scale Effect The Scale effect can be used with show/hide/toggle. This shrinks or grows an element by a percentage factor. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "scale", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "scale", {percent: 200, direction: 'horizontal'}, 2000 ); }); $("#show").click(function(){ $(".target").show( "scale", {percent: 200, direction: 'vertical' }, 2000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> </div> </body> </html> This will produce the following result: Click on any of the buttons Shake Effect The Shake effect can be used with effect() method. This shakes the element multiple times, vertically or horizontally. Syntax Here is the simple syntax to use this effect:
selector.effect( "shake", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#button").click(function(){ $(".target").effect( "shake", {times:4}, 1000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click the button</p> <button id="button"> Shake </button> <div class="target"> </div> </body> </html> This will produce the following result: Click the button Size Effect The Size effect can be used with effect() method. This resizes an element to a specified width and height. Syntax Here is the simple syntax to use this effect:
selector.effect( "size", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#big").click(function(){ $(".target").effect( "size", { to: {width: 200,height: 200} }, 1000 ); }); $("#small").click(function(){ $(".target").effect( "size", { to: {width: 10,height: 10} }, 1000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click any of the buttons</p> <button id="big"> Big </button> <button id="small"> Small </button> <div class="target"> </div> </body> </html> This will produce the following result: Click any of the buttons Slide Effect The Slide effect can be used with show/hide/toggle. This slides the element out of the viewport. Syntax Here is the simple syntax to use this effect:
selector.hide|show|toggle( "slide", {arguments}, seed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#hide").click(function(){ $(".target").hide( "slide", { direction: "down" }, 2000 ); }); $("#show").click(function(){ $(".target").show( "slide", {direction: "up" }, 2000 ); }); }); </script> <style> p {background-color:#bca; width:200px; border:1px solid green;} div{ width:100px; height:100px; background:red;} </style> </head> <body> <p>Click on any of the buttons</p> <button id="hide"> Hide </button> <button id="show"> Show</button> <div class="target"> </div> </body> </html> This will produce the following result: Click on any of the buttons Transfer Effect The Transfer effect can be used with effect() method. This Transfers the outline of an element to another element. It is very useful when trying to visualize interaction between two elements. Syntax Here is the simple syntax to use this effect:
selector.effect( "transfer", {arguments}, speed );
Parameters Here is the description of all the arguments:
Following is a simple example showing the usage of this effect:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jqueryui. min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function () { var i = 1 - $("div").index(this); $(this).effect("transfer",{ to: $("div").eq(i) }, 500); }); }); </script> <style> div.green { margin: 0px; width: 100px; height: 80px; background: green; border: 1px solid black; position: relative; } div.red { margin-top: 10px; width: 50px; height: 30px; background: red; border: 1px solid black; position: relative; } /* Following is required to show border while transferring.*/ .ui-effects-transfer { border: 2px solid black; } </style> </head> <body> <p>Click any of the squares:</p> <div class="green"></div> <div class="red"></div> </body> </html> This will produce the following result: Click any of the squares: |