显示(Show)


jQuery UI 实例 - 显示(Show)

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

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

.show() 演示

点击按钮预览特效。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>jQuery UI 特效 - .show() 演示</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: 100 };
  28.       } else if ( selectedEffect === "size" ) {
  29.         options = { to: { width: 280, height: 185 } };
  30.       }
  31.  
  32.       // 运行特效
  33.       $( "#effect" ).show( selectedEffect, options, 500, callback );
  34.     };
  35.  
  36.     // 回调函数
  37.     function callback() {
  38.       setTimeout(function() {
  39.         $( "#effect:visible" ).removeAttr( "style" ).fadeOut();
  40.       }, 1000 );
  41.     };
  42.  
  43.     // 根据选择菜单值设置特效
  44.     $( "#button" ).click(function() {
  45.       runEffect();
  46.       return false;
  47.     });
  48.  
  49.     $( "#effect" ).hide();
  50.   });
  51.   </script>
  52. </head>
  53. <body>
  54.  
  55. <div class="toggler">
  56.   <div id="effect" class="ui-widget-content ui-corner-all">
  57.     <h3 class="ui-widget-header ui-corner-all">显示(Show)</h3>
  58.     <p>
  59.       Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
  60.     </p>
  61.   </div>
  62. </div>
  63.  
  64.  <select name="effects" id="effectTypes">
  65.   <option value="blind">百叶窗特效(Blind Effect)</option>
  66.   <option value="bounce">反弹特效(Bounce Effect)</option>
  67.   <option value="clip">剪辑特效(Clip Effect)</option>
  68.   <option value="drop">降落特效(Drop Effect)</option>
  69.   <option value="explode">爆炸特效(Explode Effect)</option>
  70.   <option value="fold">折叠特效(Fold Effect)</option>
  71.   <option value="highlight">突出特效(Highlight Effect)</option>
  72.   <option value="puff">膨胀特效(Puff Effect)</option>
  73.   <option value="pulsate">跳动特效(Pulsate Effect)</option>
  74.   <option value="scale">缩放特效(Scale Effect)</option>
  75.   <option value="shake">震动特效(Shake Effect)</option>
  76.   <option value="size">尺寸特效(Size Effect)</option>
  77.   <option value="slide">滑动特效(Slide Effect)</option>
  78. </select>
  79.  
  80. <a href="#" id="button" class="ui-state-default ui-corner-all">运行特效</a>
  81.  
  82.  
  83. </body>
  84. </html>