隐藏(Hide)


jQuery UI 实例 - 隐藏(Hide)

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

如需了解更多有关 .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.       // 大多数的特效类型默认不需要传递选项
  24.       var options = {};
  25.       // 一些特效带有必需的参数
  26.       if ( selectedEffect === "scale" ) {
  27.         options = { percent: 0 };
  28.       } else if ( selectedEffect === "size" ) {
  29.         options = { to: { width: 200, height: 60 } };
  30.       }
  31.  
  32.       // 运行特效
  33.       $( "#effect" ).hide( selectedEffect, options, 1000, callback );
  34.     };
  35.  
  36.     // 回调函数
  37.     function callback() {
  38.       setTimeout(function() {
  39.         $( "#effect" ).removeAttr( "style" ).hide().fadeIn();
  40.       }, 1000 );
  41.     };
  42.  
  43.     // 根据选择菜单值设置特效
  44.     $( "#button" ).click(function() {
  45.       runEffect();
  46.       return false;
  47.     });
  48.   });
  49.   </script>
  50. </head>
  51. <body>
  52.  
  53. <div class="toggler">
  54.   <div id="effect" class="ui-widget-content ui-corner-all">
  55.     <h3 class="ui-widget-header ui-corner-all">隐藏(Hide)</h3>
  56.     <p>
  57.       Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
  58.     </p>
  59.   </div>
  60. </div>
  61.  
  62. <select name="effects" id="effectTypes">
  63.   <option value="blind">百叶窗特效(Blind Effect)</option>
  64.   <option value="bounce">反弹特效(Bounce Effect)</option>
  65.   <option value="clip">剪辑特效(Clip Effect)</option>
  66.   <option value="drop">降落特效(Drop Effect)</option>
  67.   <option value="explode">爆炸特效(Explode Effect)</option>
  68.   <option value="fold">折叠特效(Fold Effect)</option>
  69.   <option value="highlight">突出特效(Highlight Effect)</option>
  70.   <option value="puff">膨胀特效(Puff Effect)</option>
  71.   <option value="pulsate">跳动特效(Pulsate Effect)</option>
  72.   <option value="scale">缩放特效(Scale Effect)</option>
  73.   <option value="shake">震动特效(Shake Effect)</option>
  74.   <option value="size">尺寸特效(Size Effect)</option>
  75.   <option value="slide">滑动特效(Slide Effect)</option>
  76. </select>
  77.  
  78. <a href="#" id="button" class="ui-state-default ui-corner-all">运行特效</a>
  79.  
  80.  
  81. </body>
  82. </html>