470,590 Members | 2,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,590 developers. It's quick & easy.

I have a preload script for an image gallery that only seems to work in Safari

The following is a script that I have written that preloads images for an image gallery. The problem is that the images only preload in Safari, other browsers load each image when it is called. Any ideas?

Expand|Select|Wrap|Line Numbers
  1. imgSeries = new Array();
  2. curImg = '';
  3.  
  4. function loadkill() {
  5.     document.getElementById('loadingtxt').style.display = "none";
  6.     document.getElementById('imgone').src = imgSeries[0];
  7.     document.getElementById('imgtwo').src = imgSeries[1];
  8. }
  9.  
  10.  
  11. for (i=0; i<=104; i++) {
  12.  
  13.     if (i<10) {
  14.         i = '00' + i;
  15.     } else if (i>=10 && i<100) {
  16.         i = '0' + i;
  17.     }
  18.     curImg = 'images/img' + i + '.jpg';
  19.     imgSeries.push(curImg);
  20. }
  21.  
  22. function preloadImgs() {
  23.     // Preload Images
  24.     preload_image_object = new Image();
  25.     for (i=0; i<=imgSeries.length; i++) {
  26.          preload_image_object.src = imgSeries[i];
  27.     }
  28. }
  29.  
  30. // Begin next, previous and indexing
  31. pg = 0;
  32. imgCt = imgSeries.length - 1;
  33.  
  34. function processPrevious() {
  35.     if (document.images && pg > 0) {
  36.         pg--;
  37.         document.getElementById('imgtwo').src = imgSeries[pg+1];
  38.         document.getElementById('imgone').src = imgSeries[pg];
  39.     }
  40. }
  41.  
  42. function processNext() {
  43.     if (document.images && pg < imgCt) {
  44.         pg++;
  45.         document.getElementById('imgtwo').src = imgSeries[pg+1];
  46.         document.getElementById('imgone').src = imgSeries[pg];
  47.     }
  48.  
  49. }
Mar 30 '08 #1
2 1157
pronerd
392 Expert 256MB
Did you enable the caching attribute(s) in the HTML meta tags? If not you should be able to google for examples of them. I do not have the syntax in front of me at the moment.
Mar 31 '08 #2
Logician
210 100+
In this loop you are using i both as a counter and as an index
Expand|Select|Wrap|Line Numbers
  1. for (i=0; i<=104; i++) {
  2.  
  3.     if (i<10) {
  4.         i = '00' + i;
  5.     } else if (i>=10 && i<100) {
  6.         i = '0' + i;
  7.     }
  8.     curImg = 'images/img' + i + '.jpg';
  9.     imgSeries.push(curImg);
  10. }
In the function below you create a single Image object, then in the time it takes to execute the loop, you assign multiple source files to it, each overwriting the previous.
Expand|Select|Wrap|Line Numbers
  1.  function preloadImgs() {
  2.     // Preload Images
  3.     preload_image_object = new Image();
  4.     for (i=0; i<=imgSeries.length; i++) {
  5.          preload_image_object.src = imgSeries;
  6.     }
  7. }
  8.  
In the loop above, when i is equal to imgSeries.length, which element will be indexed?
Apr 1 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by MALdito | last post: by
9 posts views Thread by Flynn | last post: by
2 posts views Thread by Albert Spencil | last post: by
1 post views Thread by Peter Fastré | last post: by
14 posts views Thread by Eric Lindsay | last post: by
4 posts views Thread by RE Kochanski | last post: by
1 post views Thread by agatha.life | last post: by
1 post views Thread by shapper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.