Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call function after slidetoggle complete

Tags:

jquery

$(document).ready(function () {
    $("#newrecord tr:odd").addClass("odd");
    $("#newrecord tr:not(.odd)").find("li").hide();
    $("#newrecord tr:not(.odd)").hide();
    $("#newrecord tr:first-child").show();

    $("#newrecord tr.odd").click(function () {
        $("#newrecord tr:not(.odd)").show();
        $(this).next("tr").find("li").slideToggle("slow","swing");
    });
});

The following first hides all the even rows and when we click on the odd row it displays the even row and the slides down the li content of each row. I need help with when I click again the li tag slides up as I want it, but it should also hide the row. that is should call hide function on the row after slide up.

like image 784
Hrishikesh Sardar Avatar asked Jul 31 '13 16:07

Hrishikesh Sardar


People also ask

What does slideToggle do?

The . slideToggle() method animates the height of the matched elements. This causes lower parts of the page to slide up or down, appearing to reveal or conceal the items. If the element is initially displayed, it will be hidden; if hidden, it will be shown.

How to use slideToggle in javascript?

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.

How to use jQuery slideToggle?

The jQuery slideToggle() method toggles between the slideDown() and slideUp() methods. If the elements have been slid down, slideToggle() will slide them up. If the elements have been slid up, slideToggle() will slide them down.


2 Answers

$(document).ready(function () {
    $("#newrecord tr:odd").addClass("odd");
    $("#newrecord tr:not(.odd)").find("li").hide();
    $("#newrecord tr:not(.odd)").hide();
    $("#newrecord tr:first-child").show();

    $("#newrecord tr.odd").click(function () {
        $("#newrecord tr:not(.odd)").show();
        $(this).next("tr").find("li").slideToggle("slow","swing", function(){
            //What to do on toggle compelte...
        });
    });
});
like image 122
Lwyrn Avatar answered Oct 13 '22 09:10

Lwyrn


Lwyrn is correct, adding the third parameter to the slideToggle call will do it. For more control yet you can pass a plain object with all of the options you'd like as a parameter ( eg. .slideToggle( options )). You can read more about what those options can do at : http://api.jquery.com/slideToggle/#slideToggle-options

I find it useful to pass the object when I don't want the animation to queue (if a user clicks 50 times really fast, the animation will stack and keep toggling for a while -- undesired behavior).

like image 33
TorranceScott Avatar answered Oct 13 '22 11:10

TorranceScott