Sliding Effects
Explore the sliding effects in jQuery such as slideUp(), slideDown(), and slideToggle(), along with relevant examples.
We'll cover the following
Sliding effects slide certain elements up and down on a webpage. The relevant effects are discussed in detail below.
slideUp()
effect
Given a selector, the slideUp()
effect slides up and hides the set of matched elements from a webpage. We can also provide an optional speed
parameter to control the sliding speed.
In the “Slide Up” button event handler example below, we slide up the div
element in 2000 ms using the slideUp()
effect in line 3.
slideDown()
effect
Given a selector, the slideDown()
effect slides down and displays hidden elements present in the set of matched elements on the webpage. We can also provide an optional speed
parameter to control the sliding speed.
For example, in the “Slide Down” button event handler below, we slide down and display the hidden div
element in 3000 ms using the slideDown()
effect in line 7.
slideToggle()
effect
The slideToggle()
effect is a combination of slideUp()
and slideDown()
. When given a selector, if the matched elements are in a visible state, the slideToggle()
effect slides elements up and out of the webpage. Similarly, if the matched elements are in a hidden state, the effect slides them back down onto the webpage.
Check out this behavior in this below example. In the “Toggle Slide” button event handler, we toggle between sliding up and sliding down the div
element using the slideToggle()
effect in line 3.