# .toggle()
Categories: [Effects](http://www.css88.com/jquery-ui-api/category/effects/ "View all posts in Effects") | [Effects Core](http://www.css88.com/jquery-ui-api/category/effects-core/ "View all posts in Effects Core") | [Method Overrides](http://www.css88.com/jquery-ui-api/category/overrides/ "View all posts in Method Overrides") | [Methods](http://www.css88.com/jquery-ui-api/category/methods/ "View all posts in Methods")
## .toggle( effect [, options ] [, duration ] [, complete ] )Returns: [jQuery](http://api.jquery.com/Types/#jQuery)
**Description:** 使用自定義特效顯示或隱藏匹配的元素。
* #### [.toggle( effect [, options ] [, duration ] [, complete ] )](#toggle-effect-options-duration-complete)
* **effect**Type: [String](http://api.jquery.com/Types/#String)一個字符串,指示哪個[特效](/category/effects/)被使用。
* **options**Type: [Object](http://api.jquery.com/Types/#Object)特效選項和[緩沖函數](/easings/)。
* **duration** (default: `400`)Type: [Number](http://api.jquery.com/Types/#Number) or [String](http://api.jquery.com/Types/#String)一個字符串或者數字決定動畫將運行多久。(愚人碼頭注:三種預定速度的字符串("slow", "normal", 或 "fast")或表示動畫時長的毫秒數值(如:1000) )
* **complete**Type: [Function](http://api.jquery.com/Types/#Function)()在動畫完成時執行的函數。
* #### [.toggle( options )](#toggle-options)
* **options**Type: [Object](http://api.jquery.com/Types/#Object)全部動畫選項。 只有一個必須設置的屬性`effect`。
* **effect**Type: [String](http://api.jquery.com/Types/#String)一個字符串,指示哪個[特效](/category/effects/)被使用。
* **easing** (default: `"swing"`)Type: [String](http://api.jquery.com/Types/#String)一個字符串,表示過渡使用哪種 [緩動 函數](/easings/)。
* **duration** (default: `400`)Type: [Number](http://api.jquery.com/Types/#Number) or [String](http://api.jquery.com/Types/#String)一個字符串或者數字決定動畫將運行多久。(愚人碼頭注:三種預定速度的字符串("slow", "normal", 或 "fast")或表示動畫時長的毫秒數值(如:1000) )
* **complete**Type: [Function](http://api.jquery.com/Types/#Function)()在動畫完成時執行的函數。
* **queue** (default: `true`)Type: [Boolean](http://api.jquery.com/Types/#Boolean) or [String](http://api.jquery.com/Types/#String)一個布爾值,指示是否將動畫放置在效果隊列中。如果為false時,將立即開始動畫。 **從jQuery1.7開始**,隊列選項也可以接受一個字符串,在這種情況下, 在動畫被添加到由該字符串表示的隊列中。
這個插件擴展了jQuery中的[`.toggle()`](http://api.jquery.com/toggle)方法。 如果沒有加載 jQuery UI,調用`.toggle()`方法可能不會失敗,因為方法仍然存在。 然而,預期的行為(愚人碼頭注:指平滑過渡動畫效果)將不會發生。
## Example:
#### 使用折疊特效來切換顯示一個div。
```
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>toggle demo</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<style>
div {
width: 100px;
height: 100px;
background: #ccc;
border: 1px solid #000;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
</head>
<body>
<button>toggle the div</button>
<div></div>
<script>
$( "button" ).click(function() {
$( "div" ).toggle( "fold", 1000 );
});
</script>
</body>
</html>
```
- 索引
- Effects
- .addClass()
- Blind Effect
- Bounce Effect
- Clip Effect
- Color Animation
- Drop Effect
- Easings
- .effect()
- Explode Effect
- Fade Effect
- Fold Effect
- .hide()
- Highlight Effect
- Puff Effect
- Pulsate Effect
- .removeClass()
- Scale Effect
- Shake Effect
- .show()
- Size Effect
- Slide Effect
- .switchClass()
- .toggle()
- .toggleClass()
- Transfer Effect
- Effect Core
- .addClass()
- Color Animation
- .effect()
- .hide()
- .removeClass()
- .show()
- .switchClass()
- .toggle()
- .toggleClass()
- Interactions
- Draggable Widget
- Droppable Widget
- Mouse Interaction
- Resizable Widget
- Resizable Widget
- Selectable Widget
- Sortable Widget
- Method Overrides
- .addClass()
- .focus()
- .hide()
- .position()
- .removeClass()
- .show()
- .toggle()
- .toggleClass()
- Methods
- .disableSelection()
- .effect()
- .enableSelection()
- .focus()
- .hide()
- .position()
- .removeUniqueId()
- .scrollParent()
- .show()
- .toggle()
- .uniqueId()
- .zIndex()
- Selectors
- :data() Selector
- :focusable Selector
- :tabbable Selector
- Theming
- CSS 框架(CSS Framework)
- Icons
- Stacking Elements
- UI Core
- :data() Selector
- .disableSelection()
- .enableSelection()
- .focus()
- :focusable Selector
- .removeUniqueId()
- .scrollParent()
- :tabbable Selector
- .uniqueId()
- .zIndex()
- Utilities
- Easings
- Widget Factory
- Widget Plugin Bridge
- Mouse Interaction
- .position()
- Widgets
- Accordion Widget
- Autocomplete Widget
- Button Widget
- Datepicker Widget
- Dialog Widget
- Menu Widget
- Progressbar Widget
- Slider Widget
- Spinner Widget
- Tabs Widget
- Tooltip Widget