Latest web development tutorials

jQuery UI example - switching (Toggle)

Use custom effects to show or hide the matched elements.

For more information about .toggle() details of the methods, see the API documentation .toggle () .

.toggle () Demo

Click the button to preview effects.

<! Doctype html>
<Html lang = "en">
<Head>
  <Meta charset = "utf-8">
  <Title> jQuery UI Effects - .toggle () Demo </ title>
  <Link rel = "stylesheet" href = "// code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <Script src = "// code.jquery.com/jquery-1.9.1.js"> </ script>
  <Script src = "// code.jquery.com/ui/1.10.4/jquery-ui.js"> </ script>
  <Link rel = "stylesheet" href = "http://jqueryui.com/resources/demos/style.css">
  <Style>
  .toggler {
    width: 500px;
    height: 200px;
  }
  #button {
    padding: .5em 1em;
    text-decoration: none;
  }
  #effect {
    position: relative;
    width: 240px;
    height: 135px;
    padding: 0.4em;
  }
  #effect h3 {
    margin: 0;
    padding: 0.4em;
    text-align: center;
  }
  </ Style>
  <Script>
  $ (Function () {
    // Run the currently selected effect function runEffect () {
      // Derive effects type var selectedEffect = $ ( "#effectTypes") .val ();
 
      // Most of the effects do not need to type the default delivery options var options = {};
      // Some special effects with the required parameters if (selectedEffect === "scale") {
        options = {percent: 0};
      } Else if (selectedEffect === "size") {
        options = {to: {width: 200, height: 60}};
      }
 
      // Run effects $ ( "#effect") .toggle (selectedEffect, options, 500);
    };
 
    // Set the value according to the selected menu effects $ ( "#button") .click (function () {
      runEffect ();
      return false;
    });
  });
  </ Script>
</ Head>
<Body>
 
<Div class = "toggler">
  <Div id = "effect" class = "ui-widget-content ui-corner-all">
    <H3 class = "ui-widget-header ui-corner-all"> switching (Toggle) </ h3>
    <P>
      Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
    </ P>
  </ Div>
</ Div>
 
<Select name = "effects" id = "effectTypes">
  <Option value = "blind"> Shades effects (Blind Effect) </ option>
  <Option value = "bounce"> rebound effects (Bounce Effect) </ option>
  <Option value = "clip"> Clip effects (Clip Effect) </ option>
  <Option value = "drop"> Landing effects (Drop Effect) </ option>
  <Option value = "explode"> explosion effects (Explode Effect) </ option>
  <Option value = "fold"> folding effects (Fold Effect) </ option>
  <Option value = "highlight"> highlight effects (Highlight Effect) </ option>
  <Option value = "puff"> expansion effects (Puff Effect) </ option>
  <Option value = "pulsate"> beat effects (Pulsate Effect) </ option>
  <Option value = "scale"> Zoom effects (Scale Effect) </ option>
  <Option value = "shake"> Vibration effects (Shake Effect) </ option>
  <Option value = "size"> Size effects (Size Effect) </ option>
  <Option value = "slide"> slide effects (Slide Effect) </ option>
</ Select>
 
<a href="#" id="button" class="ui-state-default ui-corner-all"> run effects </a>
 
 
</ Body>
</ Html>