开发者

jquery call back function

I have a call back function as follows

$('#lnkClientData').click(function() {


        $('#clientdiv').slideToggle(functio开发者_开发问答n(){
            if($('#lnkClientData').hasClass('open'))
            {

                $('#divnext').slideToggle();
                $('#lnkClientData').removeClass('open').addClass('close');
            }
            else
            {

             $('#divnext').slideToggle();
             $('#lnkClientData').removeClass('close').addClass('open');
            }
        }
        );
     });

I want the $('#divnext').slideToggle(); code to be executed before the outside $('#clientdiv').slideToggle() function.... Right now the outside function gets called first....what I am trying to do is hide an anchor when a div slides in...but his happens before the div slides in...

  if($('#clientDiv').is(':visible'))
             {
             alert('');
               //  $('#divnext').hide();
                 //$('#clientDiv').slideToggle(); // Or whatever animation you want
             }
             else
             {
                 //$('#clientDiv').slideToggle(function() // Or whatever animation   you   want
                 //{
                   //  $('#divnext').show();
                 //});
             }


You just need to reorder your code then (without knowing the specifics of your slideToggle implementation, I'm assuming your parameter is a callback when the slide is finished)

 $('#divnext').slideToggle(function()
 {
     // Code here executes after slide is finished but before clientdiv starts
     $('#clientdiv').slideToggle(function()
     {
          // Code here executes after both slides are done
     });
 });

EDIT:

In your situation, simply using one slideToggle method to show / hide the client div is not the best idea.

 if($('#clientDiv').is(':visible'))
 {
     $('#yourLink').hide();
     $('#clientDiv').slideDown(); // Or whatever animation you want
 }
 else
 {
     $('#clientDiv').slideUp(function() // Or whatever animation you want
     {
         $('#yourLink').show();
     });
 }


Code code is setup to toggle the lnkClientData then when that is done toggle the clientdiv, if you swap them around ie:

$('#divnext').click(function() {
    $('#clientdiv').slideToggle(function(){
        if($('#lnkClientData').hasClass('open'))
        {

            $('#lnkClientData').slideToggle();
            $('#lnkClientData').removeClass('open').addClass('close');
        }
        else
        {

         $('#lnkClientData').slideToggle();
         $('#lnkClientData').removeClass('close').addClass('open');
        }
    }
    );
 });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜