2010-07-10 38 views
0

我使用gpgraph庫進行圖表繪製。我需要dinamicaly創建圖表,所以我使用它的jquery。在圖像加載後使用slideDown

看這個劇本請

$("#graph").click(function(u) 
{ 
    var f = 502; //just for example 
    $("#graph_content").html('<img src="mygraph.php?value1='+f+'" />'); 
    $("#graph_content").slideDown(600); 
    u.stopPropagation(); 
}); 

mygraph.php我生成圖形的形象,取決於value1

但我需要slideDown() div加載後的圖像。在我的情況下,當它加載一個圖像,它已經滑落了一個div,所以我失去了我想要的效果。 我無法想象我如何在這裏使用load方法?

也許你會幫我:)

感謝

回答

2
$("#graph").click(function(u) { 
    var f = 502; 
    $("#graph_content").html('<img src="mygraph.php?value1='+f+'" id="image" />'); 
    $("#image").load(function(){ 
    $("#graph_content").slideDown(600); 
    }); 
    u.stopPropagation(); 
});​ 

或者這也應該工作:

$("#graph").click(function(u) { 
    var f = 502; 
    $('<img src="mygraph.php?value1='+f+'" />') 
    .load(function(){ 
     $("#graph_content").slideDown(600); 
    }) 
    .appendTo("#graph_content"); 

    u.stopPropagation(); 
});​ 

如果#graph_content元素爲空。

+0

我喜歡你的解決方案。非常感謝;) – Simon 2010-07-10 19:14:42

+0

沒問題,夥計:) – galambalazs 2010-07-10 19:25:39