
Slide in Jquery
In jQuery, slide effects are used to animate the sliding motion of elements, either sliding them up (hide) or sliding them down (show). jQuery provides several methods to create smooth sliding effects, such as .slideDown()
, .slideUp()
, and .slideToggle()
.
Here's a detailed guide on slide effects in jQuery:
? 1. .slideDown()
The .slideDown()
method is used to reveal a hidden element by sliding it down.
? Syntax
$(selector).<button "#showBtn").click(function() { $("#content").slideDown(); });</script>
In this example, clicking the "Show Content" button will make the #content
div slide down and appear.
? 2. .slideUp()
The .slideUp()
method is used to hide an element by sliding it up.
? Syntax
$(selector).<button "#hideBtn").click(function() { $("#content").slideUp(); });</script>
In this example, clicking the "Hide Content" button will make the #content
div slide up and disappear.
? 3. .slideToggle()
The .slideToggle()
method is used to toggle the visibility of an element with a sliding effect. If the element is visible, it will slide up (hide). If it is hidden, it will slide down (show).
? Syntax
$(selector).<button "#toggleBtn").click(function() { $("#content").slideToggle(); });</script>
In this example, clicking the "Toggle Content" button will toggle the visibility of the #content
div with a sliding effect.
? 4. Custom Speed and Easing
You can specify custom speeds and easing effects. Here’s an example where the sliding effect takes 1000 milliseconds (1 second), and the easing is "swing"
:
$(<button "#showBtn").click(function() { $("#content").slideDown(1000, function() { alert("Slide down completed!"); }); });</script>
In this example, once the slide-down effect completes, an alert will appear with the message "Slide down completed!".
? Summary of Slide Methods in jQuery
Method | Description |
---|---|
.slideDown() | Slides an element down (makes it visible). |
.slideUp() | Slides an element up (hides it). |
.slideToggle() | Toggles the sliding motion (showing or hiding the element). |