Dealing with multiple image load events
Adam Beguelin
3 posts
|
I have some code that creates uses a Template to create a bunch of img links. After the images load, I want the code to then manipulate the DOM and add more img links. Is there some way to use Element.observe in order to know when all the images have loaded? I tried observing ‘load’ on the div that contains the images, but that didn’t work. There are a bunch of images (up to 1,000) so I don’t want to use Element.observe() on each image. Element.observe(window, ‘load’, ...) seems to work once, but not after a second set of images are loaded. Suggestions? |
Christophe P...
28 posts
|
Hey Adam, AFAIK, the From a higher standpoint, I fear for your page’s performance when I hear you’re creating up to 1,000 images in JS, client-side, using Templates. Can’t you offload that to the server? Or at least use chunks, not just a one-image-at-a-time approach… ‘HTH |
Adam Beguelin
3 posts
|
thanks for the quick response. what’s the difference between HTML injection and DOM injection? do you mean using inject()? Isn’t it DOM injection since I’m doing $(elt).insert? I’m using the Truveo API to get a list of videos and then putting the images into a div. Here’s the line that does the Element.insert: TVS.VideoSet.Video.each(function(vid){$(‘imageContainer’).insert(tpl.evaluate(vid))}) The each loop iterates up to 50 times. But I want to go back and fill the array (calling Truveo again) and then add the resulting images in the next round, after all the images have loaded from the current round. You can see one version of this experiment here: I was also hoping to just keep around the last N images, sliding in new ones in some animated way. I’ve added a unique id (again from the Truveo result set) so I could build a hash of the existing images, and then just remove ones that aren’t in the new result set. I don’t have control of the server since I’m using the Truveo API. I suppose I could use my web server to get the data from Truveo and then update the page that way. Maybe for version 2 of this exercise. But for now I’m using this as an exercise to learn Prototype using your excellent book. :-) |
Christophe P...
28 posts
|
No I mean not using inject, or anything that relies on
The book explains both, read it up! :-) |
4 posts, 2 voices
