jQuery UI 实例 - 切换(Toggle)

小灰灰 2024-03-23 10:46 156阅读 0赞

使用自定义效果来显示或隐藏匹配的元素。

如需了解更多有关 .toggle() 方法的细节,请查看 API 文档 .toggle()。

.toggle() 演示

点击按钮预览特效。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI 特效 - .toggle() 演示</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  8. <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="http://jqueryui.com/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. // 运行当前选中的特效
  34. function runEffect() {
  35. // 从中获取特效类型
  36. var selectedEffect = $( "#effectTypes" ).val();
  37. // 大多数的特效类型默认不需要传递选项
  38. var options = {};
  39. // 一些特效带有必需的参数
  40. if ( selectedEffect === "scale" ) {
  41. options = { percent: 0 };
  42. } else if ( selectedEffect === "size" ) {
  43. options = { to: { width: 200, height: 60 } };
  44. }
  45. // 运行特效
  46. $( "#effect" ).toggle( selectedEffect, options, 500 );
  47. };
  48. // 根据选择菜单值设置特效
  49. $( "#button" ).click(function() {
  50. runEffect();
  51. return false;
  52. });
  53. });
  54. </script>
  55. </head>
  56. <body>
  57. <div class="toggler">
  58. <div id="effect" class="ui-widget-content ui-corner-all">
  59. <h3 class="ui-widget-header ui-corner-all">切换(Toggle)</h3>
  60. <p>
  61. Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
  62. </p>
  63. </div>
  64. </div>
  65. <select name="effects" id="effectTypes">
  66. <option value="blind">百叶窗特效(Blind Effect)</option>
  67. <option value="bounce">反弹特效(Bounce Effect)</option>
  68. <option value="clip">剪辑特效(Clip Effect)</option>
  69. <option value="drop">降落特效(Drop Effect)</option>
  70. <option value="explode">爆炸特效(Explode Effect)</option>
  71. <option value="fold">折叠特效(Fold Effect)</option>
  72. <option value="highlight">突出特效(Highlight Effect)</option>
  73. <option value="puff">膨胀特效(Puff Effect)</option>
  74. <option value="pulsate">跳动特效(Pulsate Effect)</option>
  75. <option value="scale">缩放特效(Scale Effect)</option>
  76. <option value="shake">震动特效(Shake Effect)</option>
  77. <option value="size">尺寸特效(Size Effect)</option>
  78. <option value="slide">滑动特效(Slide Effect)</option>
  79. </select>
  80. <a href="#" id="button" class="ui-state-default ui-corner-all">运行特效</a>
  81. </body>
  82. </html>

发表评论

表情:
评论列表 (有 0 条评论,156人围观)

还没有评论,来说两句吧...

相关阅读