2010-07-10 74 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

相关问题