views:

23

answers:

2

I'm using periodic_remote_call and it updates a div with pictures.

How Can I get these pictures to be preloaded?

A: 
var myimage = new Image;
myimage.src = "/images/myimage.jpg";
bensie
SO if I wanted to loop over an array of ids and preload each one on the page how could I do this because the ids are stored as ruby variables.
Sam
A: 

I do not know hwether you still need the information, but you can indeed make a dynamic piece of JavaScript containing the ids, which you can use for your preload. Your View would contain something like this (assuming that @photo_ids is the Ruby array):

<script type="text/javascript">
var photo_ids = new Array(%< @photo_ids.join(", ") %>);
</script>

Now you can loop your photos_id in JavaScript to preload the images.

Veger