Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

jQuery UI switchClass


The jQuery UI switchClass() method is used to move from one CSS class to another CSS class, animating the transition from one state to another state.

Syntax:

Let’s see the basic syntax of jQueryUI swithClass() method: (Added in version 1.0 of jQueryUI)

  1. .switchClass( removeClassName, addClassName [, duration ] [, easing ] [, complete ] )

Parameters of switchClass() method:

removeClassName: It is a string. It represents the CSS class name or space demarcated list of class names, to be removed.

addClassName: It is of type string. It represents one or more class names which are added to the class attribute of each matched element.

duration: This is of type number or string and used to specify the time duration in millisecond. Its default value is 400.

easing: It specifies the name of the easing function to be passed to the animate() method.

complete: It is a callback method called for each element when the effect is completed for this element.

Syntax for jQuery switchClass() method: (Added in version 1.9)

The new version 1.9 of jQueryUI also supports children option, which will also animate descendant elements.

Syntax:

  1. .switchClass( removeClassName, addClassName [, options ] )

Parameters of switchClass() method: (Added in version 1.9)

removeClassName: It is a string. It represents the CSS class name or space demarcated list of class names, to be removed.

addClassName:It is of type string. It represents one or more class names which are added to the class attribute of each matched element.

options: It is used to specify all animation settings. All properties are optional. Its possible values are:

  • Duration:This is a string or number. It specifies how long the animation will run. Its default value is 400.
  • Easing:It is a string which specifies the easing function used for transition. Its default value is swing.
  • Complete:It is a callback method called for each element when the effect is completed for this element.
  • Children: This is a Boolean type and specifies whether the animation should additionally be applied to all descendants of the matched elements. Its default value is FALSE.
  • Queue:This is of Boolean type or string type and specifies whether to place the animation in the effects queue. Its default value is TRUE.

Example of jQuery UI switch class()

Let’s take an example of jQuery UI switchClass() method:

  1. <!doctype html>
  2. <html lang=“en”>
  3.    <head>
  4.       <meta charset=“utf-8”>
  5.       <title>jQuery UI Switch Class Example</title>
  6.       <link href=“http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel=“stylesheet”>
  7.       <script src=“http://code.jquery.com/jquery-1.10.2.js”></script>
  8.       <script src=“http://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
  9.       <!– CSS –>
  10.       <style>
  11.          .LargeClass
  12.          {
  13.             font-family: NewTimesRoman;
  14.             font-size: large;
  15.             font-weight: bold;
  16.             color: Red;
  17.          }
  18.          .NormalClass
  19.          {
  20.             font-family: Arial;
  21.             font-size: small;
  22.             font-weight: bold;
  23.             color: Blue;
  24.          }
  25.       </style>
  26.       <script>
  27.          $(function() {
  28.             $(‘#btnSwitch’).click(function(){
  29.                $(“.NormalClass”).switchClass(“NormalClass”,”LargeClass”,’fast’);
  30.                $(“.LargeClass”).switchClass(“LargeClass”,”NormalClass”,’fast’);
  31.                return false;
  32.             });
  33.          });
  34.       </script>
  35.    </head>
  36.    <body>
  37.       <div class=“NormalClass”>
  38.         You are here at Kreationnext
  39.       </div>
  40.       <div class=“NormalClass”>
  41. Kreationnext is commited to provide easy and point to point learning of various tutorials.
  42.       </div>
  43.       <br />
  44.       <input type=“button” id=“btnSwitch” value=“Switch Class” />
  45.    </body>
  46. </html>

Comments

comments