使用自定義效果來顯示匹配的元素。
如需了解更多有關(guān) .show()
方法的細(xì)節(jié),請(qǐng)查看 API 文檔 .show()。
點(diǎn)擊按鈕預(yù)覽特效。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI 特效 - .show() 演示</title> <link rel="stylesheet" href="/s//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="/upload/help///code.jquery.com/jquery-1.9.1.js"></script> <script src="/upload/help///code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> .toggler { width: 500px; height: 200px; } #button { padding: .5em 1em; text-decoration: none; } #effect { width: 240px; height: 135px; padding: 0.4em; position: relative; } #effect h3 { margin: 0; padding: 0.4em; text-align: center; } </style> <script> $(function() { // 運(yùn)行當(dāng)前選中的特效 function runEffect() { // 從中獲取特效類型 var selectedEffect = $( "#effectTypes" ).val(); // 大多數(shù)的特效類型默認(rèn)不需要傳遞選項(xiàng) var options = {}; // 一些特效帶有必需的參數(shù) if ( selectedEffect === "scale" ) { options = { percent: 100 }; } else if ( selectedEffect === "size" ) { options = { to: { width: 280, height: 185 } }; } // 運(yùn)行特效 $( "#effect" ).show( selectedEffect, options, 500, callback ); }; // 回調(diào)函數(shù) function callback() { setTimeout(function() { $( "#effect:visible" ).removeAttr( "style" ).fadeOut(); }, 1000 ); }; // 根據(jù)選擇菜單值設(shè)置特效 $( "#button" ).click(function() { runEffect(); return false; }); $( "#effect" ).hide(); }); </script> </head> <body> <div class="toggler"> <div id="effect" class="ui-widget-content ui-corner-all"> <h3 class="ui-widget-header ui-corner-all">顯示(Show)</h3> <p> Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi. </p> </div> </div> <select name="effects" id="effectTypes"> <option value="blind">百葉窗特效(Blind Effect)</option> <option value="bounce">反彈特效(Bounce Effect)</option> <option value="clip">剪輯特效(Clip Effect)</option> <option value="drop">降落特效(Drop Effect)</option> <option value="explode">爆炸特效(Explode Effect)</option> <option value="fold">折疊特效(Fold Effect)</option> <option value="highlight">突出特效(Highlight Effect)</option> <option value="puff">膨脹特效(Puff Effect)</option> <option value="pulsate">跳動(dòng)特效(Pulsate Effect)</option> <option value="scale">縮放特效(Scale Effect)</option> <option value="shake">震動(dòng)特效(Shake Effect)</option> <option value="size">尺寸特效(Size Effect)</option> <option value="slide">滑動(dòng)特效(Slide Effect)</option> </select> <a href="#" id="button" class="ui-state-default ui-corner-all">運(yùn)行特效</a> </body> </html>