<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Preloading images.</title>
	<link>http://ask.metafilter.com/50885/Preloading-images/</link>
	<description>Comments on Ask MetaFilter post Preloading images.</description>
	<pubDate>Tue, 14 Nov 2006 08:17:36 -0800</pubDate>
	<lastBuildDate>Tue, 14 Nov 2006 08:17:36 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Preloading images.</title>
		<link>http://ask.metafilter.com/50885/Preloading-images</link>	
		<description>How to wait until images being preloaded by JavaScript Image objects are complete? &lt;br /&gt;&lt;br /&gt; I have X number of thumbnails and I would like to wait until they are all loaded in full before I make the page visible.  Each JavaScript Image object comes with a imgObj.complete boolean which becomes true when the entire image is loaded.  I cannot simply put this in a while loop and wait because JavaScript is single-threaded.  The image objects also come with an onload event that is supposed to be triggered when the entire image has been loaded, however this is not the case.  Often the event is triggered without the entire image being loaded.  Solutions to this problem are graciously welcome.  Thank you.</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.50885</guid>
		<pubDate>Tue, 14 Nov 2006 08:00:29 -0800</pubDate>
		<dc:creator>hcastro</dc:creator>
		
			<category>javascript</category>
		
			<category>images</category>
		
			<category>webpage</category>
		
			<category>design</category>
		
			<category>slideshow</category>
		
			<category>thumbnails</category>
		
			<category>preload</category>
		
			<category>load</category>
		
			<category>onload</category>
		
			<category>complete</category>
		
	</item> <item>
		<title>By: IshmaelGraves</title>
		<link>http://ask.metafilter.com/50885/Preloading-images#770673</link>	
		<description>&lt;i&gt;I cannot simply put this in a while loop and wait because JavaScript is single-threaded.&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
Well, you could use setTimeout to check asynchronously whether the image is loaded every half-second or so. But that&apos;s kind of a hack.&lt;br&gt;
&lt;br&gt;
&lt;i&gt;The image objects also come with an onload event that is supposed to be triggered when the entire image has been loaded, however this is not the case.&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
The onload event on images has worked for me. What do you mean by &quot;loaded,&quot; and on which browsers is it not performing as expected?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.50885-770673</guid>
		<pubDate>Tue, 14 Nov 2006 08:17:36 -0800</pubDate>
		<dc:creator>IshmaelGraves</dc:creator>
	</item><item>
		<title>By: rajbot</title>
		<link>http://ask.metafilter.com/50885/Preloading-images#770729</link>	
		<description>yeah, I would use the onload event. This isn&apos;t great code, but might work for you:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
var i;&lt;br&gt;
var imgArray=new Array();&lt;br&gt;
var numLoaded=0;&lt;br&gt;
&lt;br&gt;
for (i=0;i&amp;lt;X;i++) {&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;imgArray[i] = new Image();&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;imgArray[i].onload = function() {&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;numLoaded++;&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if(numLoaded==X) {&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;doNextTask();&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;}&lt;br&gt;
&#160;&#160;&#160;&#160;&#160;img.=&apos;http://example.com/&apos;+X+&apos;.jpg&apos;;&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.50885-770729</guid>
		<pubDate>Tue, 14 Nov 2006 09:01:59 -0800</pubDate>
		<dc:creator>rajbot</dc:creator>
	</item><item>
		<title>By: hcastro</title>
		<link>http://ask.metafilter.com/50885/Preloading-images#770861</link>	
		<description>Well it seems that the .onload event works fine in Firefox &amp;amp; Internet Explorer.  I must have been implementing it wrong before.  I appreciate your help.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.50885-770861</guid>
		<pubDate>Tue, 14 Nov 2006 10:39:05 -0800</pubDate>
		<dc:creator>hcastro</dc:creator>
	</item>
	</channel>
</rss>
