jQuery UI API - .toggleClass()
Category
Effects | Effects Core | Method Overrides
Usage
**Description:** Adds or removes one or more classes for each element in the matched set as the animation style changes, depending on whether the class exists and the value of the switch parameter.
Returns:jQuery
.toggleClass( className [, switch ] [, duration ] [, easing ] [, complete ] )
| Parameters | Type | Description | Default value |
|---|---|---|---|
| ClassName | String | One or more class names to toggle for each element in the matched set, separated by spaces. | |
| switch | Boolean | A boolean value specifying whether the class should be added or removed. | |
| duration | Number or String | A string or a number specifying how long the animation will run. | 400 |
| easing | String | A string indicating the easing function in Vue 3. | swing |
| complete | Function() | function to call once the animation is complete. |
.toggleClass( className [, switch ] [, options ] )
| Parameters | Type | Description |
|---|---|---|
| ClassName | String | One or more class names to toggle for each element in the matched set, separated by spaces. |
| switch | Boolean | A boolean value specifying whether the class should be added or removed. |
| options | Object | All animation settings. All properties are optional.
|
400)
Type: Number or String
Description: a string or a number specifying how long the animation will run.
swing)
Type: String
Description: a string indicating the easing function in Vue 3.
Type: Function()
Description: the function to call once the animation is complete.
false)
Type: Boolean
Description: whether to apply the animation to all descendants of the matched elements. Use this feature with caution, because determining whether an element is a descendant of the animated element is expensive and grows linearly with the number of descendants.
true)
Type: Boolean or String
Description: a boolean indicating whether to place the animation in the effects queue. If false, the animation starts immediately.As of jQuery 1.7,the queue option also accepts a string, in which case the animation is added to the queue represented by that string.
Similar to native CSS transitions, jQuery UI class animations provide a smooth transition from one state to another while ensuring that all details of the style changes are handled through CSS rather than JavaScript. All class animation methods, including .toggleClass(), allow custom animation durations and easing functions, and also provide a callback when the animation completes.
Not all styles can be animated. For example, background images cannot be animated. Any style that cannot be animated will change at the end of the animation.
This plugin extends jQuery's built-in .toggleClass() method. If jQuery UI is not loaded, calling the .toggleClass() method does not fail directly, because the method exists in jQuery. However, the expected behavior will not occur.
Example
Toggles the class "big-blue" on the matched elements.
.toggleClass() 演示