2010-03-09 3 views
7

Bir sürgü animasyonu var ama clX.click olayında #close div hides animasyonu yapmadan önce -250px kaldı. Animasyon tamamlanana ve sonra #close div 'i gizleyene kadar beklemek nasıl?jQuery olay sırası ve animasyon tamamlanana kadar beklemek

$(document).ready(function() { 
     $("#open").click(function() { 
      if ($("#close").is(":hidden")) { 
       $("#open").animate({ 
        marginLeft: "-32px" 
       }, 200); 

       $("#close").show(); 
       $("#close").animate({ 
        marginLeft: "250px" 
       }, 500); 
      } 
     }); 
     $("#clX").click(function() { 
      $("#close").animate({ 
       marginLeft: "-250px" 
      }, 500); 

      $("#open").animate({ 
       marginLeft: "0px" 
      }, 200); 

      $("#close").hide(); 
     }); 
    }); 

cevap

11

Animasyona bir geri arama işlevi ekleyebilirsiniz. Animasyon bittiğinde ateş yakılırdı.

$('#clX').click(function() { 
    $('#close').animate({ 
    marginLeft: "-250px" 
    }, 500, function() { 
    // Animation complete. 
    $("#close").hide(); 
    //i supose $this.hide() <br/>would work also and it is more efficient. 
    }); 
}); 
+0

@patxi: beklemiyorsun, bitince başka bir şey yapmak için animasyon talimat. –

+0

Bitti! Ama $ this.hide(); düzgün çalışmıyor. –

4

@Hasan, galiba anlamına $ (this) Bir başka deyişle

var closeable = $('#close'); 
$('#clx').bind('click', function(){ 
    // $(this) === $('#clx') 
    closeable.stop().animate({marginLeft:'-250px'},{ 
    duration: 500, 
    complete: function(){ 
     $(this).hide(); 
     // $(this) === closeable; 
    } 
    }); 
});