jQuery UI API - .switchClass()
Category
Effects | Effects Core | Method Overrides
Usage
**Description:** Adds and removes specified classes for each element in the matched set as the animation style changes.
Returns:jQuery
.switchClass( removeClassName, addClassName [, duration ] [, easing ] [, complete ] )
| Parameters | Type | Description | Default value |
|---|---|---|---|
| removeClassName | String | One or more class names to remove from the class attribute of each matched element, separated by spaces. | |
| addClassName | String | One or more class names to add to the class attribute of each matched element; multiple class names are separated by spaces. | |
| 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. |
.switchClass( removeClassName, addClassName [, options ] )
| Parameters | Type | Description |
|---|---|---|
| removeClassName | String | One or more class names to remove from the class attribute of each matched element, separated by spaces. |
| addClassName | String | One or more class names to add to the class attribute of each matched element; multiple class names are separated by spaces. |
| 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.
.switchClass() The method lets you add and remove classes during an animation transition.
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 .switchClass(), 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 .switchClass() method. If jQuery UI is not loaded, calling .switchClass() method does not fail directly, because the method exists in jQuery. However, the expected behavior will not occur.
Example
adds the class "blue" to the matched elements and removes the class "big" from them.
.switchClass() 演示