2011-02-22 68 views
1

這是我在stackoverflow上的第一篇文章,但是閱讀了很多並學習。jQuery加載slideDown效果的問題

我使用了一個jquery函數,該函數用.load函數加載wordpress主題中的帖子。

但現在我有一個問題,我不能自己解決。

$(document).ready(function(){ 

$.ajaxSetup({cache:false}); 
$("#thumbs a").click(function(){ 
var post_id = $(this).attr("rel") 
$("#your_post_here").slideDown("1200", function() { 
$("#your_post_here").html("<img src='http://localhost/wp-content/themes/insp/images/ajax-loader.gif' />"); 
$("#your_post_here").load("http://<?php echo $_SERVER[HTTP_HOST]; ?>/triqui-ajax/",{id:post_id}); 
}); 

    return false; 

}); 

$("a.close").live("click", function(){ 
    $("#intro").slideUp(1200); 
    return false; 
}); 

});

問題是我無法在它加載之前將它滑到slideDown。是否有人對可能出現什麼問題有所瞭解?

Everyting工作正常,除了slideDown效果

編輯:

也許我弄錯了,就把不能真正得到它的工作。

我這樣說,這是錯的嗎?

$("#thumbs a").click(function(){ 
    var post_id = $(this).attr("rel") 
$("#your_post_here").slideDown("200", function() { 
    $("#your_post_here").html("<img src='http://localhost/wp-content/themes/insp/images/ajax-loader.gif' />"); 
    $("#your_post_here").load("http://<?php echo $_SERVER[HTTP_HOST]; ?>/triqui-ajax/",{id:post_id}); 
}); 
+0

你在$(文件)。就緒把這個包(http://api.jquery.com/ready/)?我有時會忘記這樣做,並導致UI效果不會發生。 – 2011-02-22 18:23:28

+0

是的,我已經做到了。 – 2011-02-22 19:44:26

回答

5

你需要把​​在.slideDown()的回調。

$("#your_post_here").slideDown("200", function() { 
    $("#your_post_here").html("<img src='http://localhost/wp-content/themes/insp/images/ajax-loader.gif' />"); 
    $("#your_post_here").load("http://<?php echo $_SERVER[HTTP_HOST]; ?>/triqui-ajax/",{id:post_id}); 
}); 

//編輯:

$("#your_post_here").slideDown("200", function() { 
    $(this).html("<img src='http://localhost/wp-content/themes/insp/images/ajax-loader.gif' />"); 
    $(this).load("http://<?php echo $_SERVER[HTTP_HOST]; ?>/triqui-ajax/",{id:post_id}); 
});