Toggle - Display or hide elements using custom effects. Click the button above to preview the effect.


SUBMITTED BY: jlolk3r

DATE: Jan. 15, 2016, 1:46 a.m.

FORMAT: HTML

SIZE: 2.6 kB

HITS: 547

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

comments powered by Disqus