Does anyone know a good way to fire a callback function on the slideUp event only during a slideToggle? The default callback function fires on both slideUp and slideDown.
Thanks!
jQuery slideToggle () method is used to hide or display the selected DOM elements with a sliding effect. In other words, slideToggle () method toggles between slideUp () and slideDown () methods. If the DOM element is hidden, slideDown () method is run to slide it down to display it.
The slideToggle () method toggles between slideUp () and slideDown () for the selected elements. This method checks the selected elements for visibility. slideDown () is run if an element is hidden. slideUp () is run if an element is visible - This creates a toggle effect. Optional. Specifies the speed of the slide effect.
Definition and Usage. The slideUp() method slides-up (hides) the selected elements. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To slide-down (show) elements, look at the slideDown() method.
Two parameters ( speed and callback function) are passed to all the three methods, slideDown (), slideUp () and slideToggle (). In all three cases, the callback function gets fired only once the sliding effect has completely finished. To see the effect of the slideDown () method.
You can check if the element .is()
:hidden
since it'll be hidden at the end of a slide up, like this:
$(this).slideToggle(function() {
if($(this).is(":hidden")) {
alert("this was a slide up");
}
});
You can test it out here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With