JqueryUI - Display or hide elements using custom effects.


SUBMITTED BY: jlolk3r

DATE: Jan. 28, 2016, 6:53 a.m.

FORMAT: HTML

SIZE: 2.5 kB

HITS: 1707

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Effects - Toggle Demo</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  8. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="/resources/demos/style.css">
  10. <style>
  11. .toggler {
  12. width: 500px;
  13. height: 200px;
  14. }
  15. #button {
  16. padding: .5em 1em;
  17. text-decoration: none;
  18. }
  19. #effect {
  20. position: relative;
  21. width: 240px;
  22. height: 135px;
  23. padding: 0.4em;
  24. }
  25. #effect h3 {
  26. margin: 0;
  27. padding: 0.4em;
  28. text-align: center;
  29. }
  30. </style>
  31. <script>
  32. $(function() {
  33. // run the currently selected effect
  34. function runEffect() {
  35. // get effect type from
  36. var selectedEffect = $( "#effectTypes" ).val();
  37. // most effect types need no options passed by default
  38. var options = {};
  39. // some effects have required parameters
  40. if ( selectedEffect === "scale" ) {
  41. options = { percent: 0 };
  42. } else if ( selectedEffect === "size" ) {
  43. options = { to: { width: 200, height: 60 } };
  44. }
  45. // run the effect
  46. $( "#effect" ).toggle( selectedEffect, options, 500 );
  47. };
  48. // set effect from select menu value
  49. $( "#button" ).click(function() {
  50. runEffect();
  51. });
  52. });
  53. </script>
  54. </head>
  55. <body>
  56. <div class="toggler">
  57. <div id="effect" class="ui-widget-content ui-corner-all">
  58. <h3 class="ui-widget-header ui-corner-all">Toggle</h3>
  59. <p>
  60. Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
  61. </p>
  62. </div>
  63. </div>
  64. <select name="effects" id="effectTypes">
  65. <option value="blind">Blind</option>
  66. <option value="bounce">Bounce</option>
  67. <option value="clip">Clip</option>
  68. <option value="drop">Drop</option>
  69. <option value="explode">Explode</option>
  70. <option value="fold">Fold</option>
  71. <option value="highlight">Highlight</option>
  72. <option value="puff">Puff</option>
  73. <option value="pulsate">Pulsate</option>
  74. <option value="scale">Scale</option>
  75. <option value="shake">Shake</option>
  76. <option value="size">Size</option>
  77. <option value="slide">Slide</option>
  78. </select>
  79. <button id="button" class="ui-state-default ui-corner-all">Run Effect</button>
  80. </body>
  81. </html>

comments powered by Disqus