How to call a function after a slide effect?

Asked

Viewed 73 times

2

I need to take the height of a div and redeem an ifram according to the current height, so far so good.

Only I’m getting the height right after a click that gives a slideToggle in this div. And it seems to me that as yet the slide effect isn’t finished I can’t get the right height.

So how can I call this function only after the slide is complete?

$(document).on("click", "#toggleDiv" function(){
    $("#questao").slideToggle(300);
    // chamar função para pegar altura somente após o fim do slide. como?
}); 

1 answer

3


The .slideToggle() accepts a callback, or is a function that must run when the animation is finished.

You can use it like this:

$(document).on("click", "#toggleDiv" function(){
    $("#questao").slideToggle(300, function(){
        // aqui o slide já acabou
    });

});

Within that function you can use the this to access animated element. If you want height you can use $(this).height();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.