I have a real estate application that display homes.
I use AJAX to populate a fixed height/width DIV "window" with home listings.
Many times, the DIV window can be populated with literally a 1,000 or so house listings.
Each house listing includes one picture of the property and each house listing is about 100px tall (each "row" is 100px tall).
Since my DIV height is only 400px tall, only 4 house listings (of the possible thousands) are visible without scrolling at any given time.
Question:
How can I load the images in the order in which I have them listed in the DIV window. That way, the visible house images are downloaded first, and then all of the non-visible images (without scrolling) are downloaded later in the background?
UPDATE:
Note, I am not describing lazy-loading
the images. What I want to do is load the images sequentiality in the same order as I have them listing in my DIV window, starting at the top and then working down. That way, the visible images gets loaded first but still continues the download of the non-visible images without the users having to initiate the download by scrolling.
UPDATE 2
In case it helps, I have the pseudo-code below of what I'm talking about:
<html>
<script>
var allHomesJSON = ajax_call_to_json_web_service('http://example.com/city=nyc");
for (i=0; i<allHomesJSON.length; i++) {
document.getElementByID('all-homes').innerHTML += '<div class="individual-listing"><img src="allHomesJSON[i].img">Price: allHomesJSON[i].price, Sqft: allHomesJSON.sqft[i] ...';
}
</script>
<body>
<div id="all-homes" style="height:400px">
</div>
So the resulting generated HTML is something like:
<html>
<body>
<div id="all-homes" style="height:400px">
<div class="individual-listing"><img src="http://example/x.jpg">Price: $300,000, Sqft: 2000</div>
<div class="individual-listing"><img src="http://example/y.jpg">Price: $200,000, Sqft: 2000</div>
<div class="individual-listing"><img src="http://example/z.jpg">Price: $500,000, Sqft: 2000</div>
<div class="individual-listing"><img src="http://example/a.jpg">Price: $100,000, Sqft: 2000</div>
...
</div>