admin管理员组

文章数量:1291582

I have the following JQuery code

        $("#classparent").click(function () {
            $(".classsubitems").slideToggle('slow', function () {
            });
        });

I need to let JQuery run some code at begin and end of animation.

Is this possible?

Thank you

I have the following JQuery code

        $("#classparent").click(function () {
            $(".classsubitems").slideToggle('slow', function () {
            });
        });

I need to let JQuery run some code at begin and end of animation.

Is this possible?

Thank you

Share Improve this question asked Oct 31, 2011 at 13:42 OzkanOzkan 2,0416 gold badges29 silver badges43 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

Simple enough.

 $("#classparent").click(function () {         
    // before start of animation code here   
    $(".classsubitems").slideToggle('slow', function () {
        // end of animation code here in the callback
    });
 });

The code you want to execute before the animation you can place before the slideToggle method. The code you want to execute after the animation you can place in the callback function.

SlideToggle has a callback-function (it looks like you already have provided that?)

http://api.jquery./slideToggle/

For the code to be executed before the animation: the easies way to do this is simply calling it before the line with $(".classsubitems").

SlideToggle doesn't have callback method to call at the beggining but it is possible when pletes.

  $("#classparent").click(function () {
             //Code to call before animation starts
             $(".classsubitems").slideToggle('slow', function () {    
               //code to execute after the animation finish.
         });         });

本文标签: javascriptjquery do something at the begin and end of animationStack Overflow