jQuery UI Toggle

jQuery UI Toggle

jQuery toggle()方法用于根据元素是否隐藏来切换show()或hide()方法。
语法:
 $(selector).toggle(speed,callback,switch) 
toggle方法的参数:

speed: 可选。规定元素从可见到隐藏的速度(或者相反)。默认为 "0"。
callback: 可选。toggle 函数执行完之后,要执行的函数。
switch: 可选。布尔值。规定 toggle 是否隐藏或显示所有被选元素。

jQueryUI切换示例

让我们以具有爆炸效果的jQueryUI toggle()方法为例:
 <!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>jQuery UI Toggle Example</title>
      <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <!-- CSS -->
      <style>
         .toggler { width: 500px; height: 200px; }
         #button { padding: .5em 1em; text-decoration: none; }
         #effect { width: 240px; height: 155px; padding: 0.4em; position: relative; }
         #effect h3 { margin: 0; padding: 0.4em; text-align: center; }
      </style>
      <script>
         $(function() {
            function runEffect() {
               $( "#effect").toggle('explode', 300);
            };
            $( "#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>
         bianchenghao6 provides easy and point to point learning of various tutorials such as
        Java Tutorial, Core Java Tutorial, Android, Design Pattern, JavaScript, AJAX, SQL, Python etc.
         </p>
      </div>
      </div>
      <a href="#" id="button" class="ui-state-default ui-corner-all">Togglemethod with explode effect</a>
   </body>
</html>