Latest web development tutorials

jQuery UI example - special effects (Effect)

Application of an element of animation effects.

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

.effect () Demo

Click the button to preview effects.

<! Doctype html>
<Html lang = "en">
<Head>
  <Meta charset = "utf-8">
  <Title> jQuery UI Effects - .effect () 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; position: relative;}
    #button {padding: .5em 1em; text-decoration: none;}
    #effect {width: 240px; height: 135px; padding: 0.4em; position: relative;}
    #effect h3 {margin: 0; padding: 0.4em; text-align: center;}
    .ui-effects-transfer {border: 2px dotted gray;}
  </ 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 === "transfer") {
        options = {to: "#button", className: "ui-effects-transfer"};
      } Else if (selectedEffect === "size") {
        options = {to: {width: 200, height: 60}};
      }
 
      // Run effects $ ( "#effect") .effect (selectedEffect, options, 500, callback);
    };
 
    // Callback function callback () {
      setTimeout (function () {
        $ ( "#effect") .removeAttr ( "Style") .hide () fadeIn ().;
      }, 1000);
    };
 
    // 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"> special effects (Effect) </ 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 = "fade"> Fade effects (Fade 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>
  <Option value = "transfer"> transfer effects (Transfer Effect) </ option>
</ Select>
 
<a href="#" id="button" class="ui-state-default ui-corner-all"> run effects </a>
 
 
</ Body>
</ Html>

Easing Demo

This example uses HTML Canvas element, draw all easings jQuery UI provides. Click on each map to see the easing behavior. .

<! Doctype html>
<Html lang = "en">
<Head>
  <Meta charset = "utf-8">
  <Title> jQuery UI Effects - Easing 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>
  .graph {
    float: left;
    margin-left: 10px;
  }
  </ Style>
  <Script>
  $ (Function () {
    if (! $ ( "<canvas>") [0] .getContext) {
      $ ( "<Div>") .text (
        "Your browser does not support canvas, this demonstrates the need to support the canvas in the browser."
      ) .appendTo ( "#graphs");
      return;
    }
 
    var i = 0,
      width = 100,
      height = 100;
 
    $ .each ($ .easing, Function (name, impl) {
      var graph = $ ( "<div>") .addClass ( "graph") .appendTo ( "#graphs"),
        text = $ ( "<div>") .text (++ i + "." + name) .appendTo (graph),
        wrap = $ ( "<div>") .appendTo (graph) .css ( 'overflow', 'hidden'),
        canvas = $ ( "<canvas>") .appendTo (wrap) [0];
 
      canvas.width = width;
      canvas.height = height;
      var drawHeight = height * 0.8,
        cradius = 10;
        ctx = canvas.getContext ( "2d");
      ctx.fillStyle = "black";
 
      // Draw background ctx.beginPath ();
      ctx.moveTo (cradius, 0);
      ctx.quadraticCurveTo (0, 0, 0, cradius);
      ctx.lineTo (0, height - cradius);
      ctx.quadraticCurveTo (0, height, cradius, height);
      ctx.lineTo (width - cradius, height);
      ctx.quadraticCurveTo (width, height, width, height - cradius);
      ctx.lineTo (width, 0);
      ctx.lineTo (cradius, 0);
      ctx.fill ();
 
      // Draw the bottom line ctx.strokeStyle = "# 555";
      ctx.beginPath ();
      ctx.moveTo (width * 0.1, drawHeight + .5);
      ctx.lineTo (width * 0.9, drawHeight + .5);
      ctx.stroke ();
 
      // Draw the top line ctx.strokeStyle = "# 555";
      ctx.beginPath ();
      ctx.moveTo (width * 0.1, drawHeight * .3 - .5);
      ctx.lineTo (width * 0.9, drawHeight * .3 - .5);
      ctx.stroke ();
 
      // Draw easing
      ctx.strokeStyle = "white";
      ctx.beginPath ();
      ctx.lineWidth = 2;
      ctx.moveTo (width * 0.1, drawHeight);
      $ .each (New Array (width), function (position) {
        var state = position / width,
          val = impl (state, position, 0, 1, width);
        ctx.lineTo (position * 0.8 + width * 0.1,
          drawHeight - drawHeight * val * 0.7);
      });
      ctx.stroke ();
 
      // Dynamically changing clicks graph.click (function () {
        wrap
          .animate ({height: "hide"}, 2000, name)
          .delay (800)
          .animate ({height: "show"}, 2000, name);
      });
 
      graph.width (width) .height (height + text.height () + 10);
    });
  });
  </ Script>
</ Head>
<Body>
 
<Div id = "graphs"> </ div>
 
 
</ Body>
</ Html>