Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slideToggle - callback function on slideUp action only

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!

like image 418
Alex Avatar asked Nov 05 '10 15:11

Alex


People also ask

How to use slidetoggle() method in jQuery?

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.

What is the difference between the methods slidetoggle () and Slidedown ()?

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.

What is the use of slideup and Slidedown?

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.

What are the parameters passed to 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.


1 Answers

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.

like image 195
Nick Craver Avatar answered Oct 19 '22 22:10

Nick Craver