Simon
Simon

Reputation: 23141

use slideDown after image loads

i use gpgraph library for charts drawing. i need to dinamicaly create graphs, so i use jquery for it.

Look at this script please

$("#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();
});

in mygraph.php i generate the image of graphic, depend on value1.

but i need to slideDown() the div with image after it loads. in my case while it loads an image, it allready slides down a div, so i lose effect i wanted. i can't imagine how can i use load method here?

maybe you will help me:)

Thanks

Upvotes: 0

Views: 486

Answers (1)

gblazex
gblazex

Reputation: 50109

$("#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();
});​

or this should also work:

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

  u.stopPropagation();
});​

If the #graph_content element is empty.

Upvotes: 2

Related Questions