2015-10-19 105 views
2
$(document).on('click', '.selector', function(event){ 
    var id = $(this).data('id'); 
    event.stopPropagation(); 
    var $target = $(event.target); 

    $.ajax({ 
     type: "GET", 
     url: "components/display.cfc?method=displayFields&ID=" + id + "&returnformat=plain", 
     success: function(html){ 
      $('.myDiv').append(html); 
      if ($target.closest("td").attr("colspan") > 1) { 
       $target.slideUp(); 
      } else { 

       $target.closest("tr").next().find("p").slideToggle(); 
      }   
     }, 
     error: function(jqXHR,textStatus,errorThrown){ 
      console.log(textStatus);  
     } 
    });  
}); 

我需要檢查slideToggle滑動時,以便我可以重置/刪除html的值。這怎麼可能?JQuery - 檢查滑動滑動時滑動

+1

'.slideToggle()'只出現在'else'聲明 「下滑」? – guest271314

回答

1

slideToggle()函數後輸入callback;

$(document).on('click', '.selector', function(event){ 
    var id = $(this).data('id'); 
    event.stopPropagation(); 
    var $target = $(event.target); 

    $.ajax({ 
     type: "GET", 
     url: "components/display.cfc?method=displayFields&ID=" + id + "&returnformat=plain", 
     success: function(html){ 
      $('.myDiv').append(html); 
      if ($target.closest("td").attr("colspan") > 1) { 
      $target.slideUp(); 
      } else { 

       $target.closest("tr").next().find("p").slideToggle(); 
       alert("Finished"); // <- callback here 
      }   
     }, 
     error: function(jqXHR,textStatus,errorThrown){ 
      console.log(textStatus);  
     } 
    }); 
}); 
2

幻燈片切換必須做一個回調函數,這將幻燈片動畫後發生的能力。這可能適合你的情況。幻燈片切換

文檔可以在這裏讀到:http://api.jquery.com/slidetoggle/

正確使用您的具體情況:

$(someElement).slideToggle(function(){ 
    //Any code in here will be executed after the slideToggle function has finished 
});