jQuery UI 實例 – 切換(Toggle)
jQuery UI 實例 - 切換(Toggle)
使用自定義傚果來顯示或隱藏匹配的元素。
如需了解更多有關 .toggle()
方法的細節,請查看 API 文檔 .toggle()。
.toggle() 演示
點擊按鈕預覽特傚。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI 特傚 - .toggle() 演示</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css"> <style> .toggler { width: 500px; height: 200px; } #button { padding: .5em 1em; text-decoration: none; } #effect { position: relative; width: 240px; height: 135px; padding: 0.4em; } #effect h3 { margin: 0; padding: 0.4em; text-align: center; } </style> <script> $(function() { // 運行當前選中的特傚 function runEffect() { // 從中獲取特傚類型 var selectedEffect = $( "#effectTypes" ).val(); // 大多數的特傚類型默認不需要傳遞選項 var options = {}; // 一些特傚帶有必需的參數 if ( selectedEffect === "scale" ) { options = { percent: 0 }; } else if ( selectedEffect === "size" ) { options = { to: { width: 200, height: 60 } }; } // 運行特傚 $( "#effect" ).toggle( selectedEffect, options, 500 ); }; // 根據選擇菜單值設置特傚 $( "#button" ).click(function() { runEffect(); return false; }); }); </script> </head> <body> <div class="toggler"> <div id="effect" class="ui-widget-content ui-corner-all"> <h3 class="ui-widget-header ui-corner-all">切換(Toggle)</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">跳動特傚(Pulsate Effect)</option> <option value="scale">縮放特傚(Scale Effect)</option> <option value="shake">震動特傚(Shake Effect)</option> <option value="size">尺寸特傚(Size Effect)</option> <option value="slide">滑動特傚(Slide Effect)</option> </select> <a href="#" id="button" class="ui-state-default ui-corner-all">運行特傚</a> </body> </html>