Google Groups Home
Help | Sign in
Why does this not preload an image correctly?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Giant Jam Sandwich  
View profile
 More options May 11, 6:44 pm
From: Giant Jam Sandwich <hal9...@reindel.com>
Date: Sun, 11 May 2008 15:44:41 -0700 (PDT)
Local: Sun, May 11 2008 6:44 pm
Subject: Why does this not preload an image correctly?
I seem to be having a problem with some code similar to the pseudo-
code below. Assume that I am getting an XML document that has nodes
called "src" that hold image source urls, and that "someDivId" has a
display property of "none" set in the CSS.

- - -

$(function(){

   $.get( "doc.xml", function( data ) {

      $("#someDivId").append( "<img src='" + $("src[0]", data).text()
+ "' />" );
      $("#someDivId img").load(function(){
         $("#someDivId").css("display", "block");
      });

   }

});

- - -

In my code, the DIV is displaying before the image is loaded. However,
if I hard code the image into the HTML, give it an ID, and then attach
the load event to that, it works just fine. Thanks!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wizzud  
View profile
 More options May 12, 4:32 am
From: Wizzud <r...@wizzud.com>
Date: Mon, 12 May 2008 01:32:05 -0700 (PDT)
Local: Mon, May 12 2008 4:32 am
Subject: Re: Why does this not preload an image correctly?
You could simply change it around a bit...

- create the image
- assign a load handler, with a callback to append the image to the
div and show the div
- set the image src

eg
$('<img />').load(function(){
    $(this).appendTo('#someDivId').parent(show);
  })
  .attr('src', $('src[0]', data).text());

NB Not all browsers like jQuery's load() as an image preloader; you
might want to check out Ariel Flesler's preload plugin?

On May 11, 11:44 pm, Giant Jam Sandwich <hal9...@reindel.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google