jQuery UI 实例 - 隐藏(Hide)

柔光的暖阳◎ 2024-03-23 10:45 97阅读 0赞

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

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

.hide() 演示

点击按钮预览特效。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI 特效 - .hide() 演示</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 { width: 500px; height: 200px; }
  12. #button { padding: .5em 1em; text-decoration: none; }
  13. #effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
  14. #effect h3 { margin: 0; padding: 0.4em; text-align: center; }
  15. </style>
  16. <script>
  17. $(function() {
  18. // 运行当前选中的特效
  19. function runEffect() {
  20. // 从中获取特效类型
  21. var selectedEffect = $( "#effectTypes" ).val();
  22. // 大多数的特效类型默认不需要传递选项
  23. var options = {};
  24. // 一些特效带有必需的参数
  25. if ( selectedEffect === "scale" ) {
  26. options = { percent: 0 };
  27. } else if ( selectedEffect === "size" ) {
  28. options = { to: { width: 200, height: 60 } };
  29. }
  30. // 运行特效
  31. $( "#effect" ).hide( selectedEffect, options, 1000, callback );
  32. };
  33. // 回调函数
  34. function callback() {
  35. setTimeout(function() {
  36. $( "#effect" ).removeAttr( "style" ).hide().fadeIn();
  37. }, 1000 );
  38. };
  39. // 根据选择菜单值设置特效
  40. $( "#button" ).click(function() {
  41. runEffect();
  42. return false;
  43. });
  44. });
  45. </script>
  46. </head>
  47. <body>
  48. <div class="toggler">
  49. <div id="effect" class="ui-widget-content ui-corner-all">
  50. <h3 class="ui-widget-header ui-corner-all">隐藏(Hide)</h3>
  51. <p>
  52. Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
  53. </p>
  54. </div>
  55. </div>
  56. <select name="effects" id="effectTypes">
  57. <option value="blind">百叶窗特效(Blind Effect)</option>
  58. <option value="bounce">反弹特效(Bounce Effect)</option>
  59. <option value="clip">剪辑特效(Clip Effect)</option>
  60. <option value="drop">降落特效(Drop Effect)</option>
  61. <option value="explode">爆炸特效(Explode Effect)</option>
  62. <option value="fold">折叠特效(Fold Effect)</option>
  63. <option value="highlight">突出特效(Highlight Effect)</option>
  64. <option value="puff">膨胀特效(Puff Effect)</option>
  65. <option value="pulsate">跳动特效(Pulsate Effect)</option>
  66. <option value="scale">缩放特效(Scale Effect)</option>
  67. <option value="shake">震动特效(Shake Effect)</option>
  68. <option value="size">尺寸特效(Size Effect)</option>
  69. <option value="slide">滑动特效(Slide Effect)</option>
  70. </select>
  71. <a href="#" id="button" class="ui-state-default ui-corner-all">运行特效</a>
  72. </body>
  73. </html>

发表评论

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

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

相关阅读