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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matt9807
    New Member
    • Mar 2008
    • 1

    #1

    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?

    [CODE=javascript]imgSeries = new Array();
    curImg = '';

    function loadkill() {
    document.getEle mentById('loadi ngtxt').style.d isplay = "none";
    document.getEle mentById('imgon e').src = imgSeries[0];
    document.getEle mentById('imgtw o').src = imgSeries[1];
    }


    for (i=0; i<=104; i++) {

    if (i<10) {
    i = '00' + i;
    } else if (i>=10 && i<100) {
    i = '0' + i;
    }
    curImg = 'images/img' + i + '.jpg';
    imgSeries.push( curImg);
    }

    function preloadImgs() {
    // Preload Images
    preload_image_o bject = new Image();
    for (i=0; i<=imgSeries.le ngth; i++) {
    preload_image_o bject.src = imgSeries[i];
    }
    }

    // Begin next, previous and indexing
    pg = 0;
    imgCt = imgSeries.lengt h - 1;

    function processPrevious () {
    if (document.image s && pg > 0) {
    pg--;
    document.getEle mentById('imgtw o').src = imgSeries[pg+1];
    document.getEle mentById('imgon e').src = imgSeries[pg];
    }
    }

    function processNext() {
    if (document.image s && pg < imgCt) {
    pg++;
    document.getEle mentById('imgtw o').src = imgSeries[pg+1];
    document.getEle mentById('imgon e').src = imgSeries[pg];
    }

    }[/CODE]
    Last edited by gits; Mar 31 '08, 07:58 AM. Reason: added code tags
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    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.

    Comment

    • Logician
      New Member
      • Feb 2007
      • 210

      #3
      In this loop you are using i both as a counter and as an index
      Originally posted by matt9807
      [CODE=javascript]
      for (i=0; i<=104; i++) {

      if (i<10) {
      i = '00' + i;
      } else if (i>=10 && i<100) {
      i = '0' + i;
      }
      curImg = 'images/img' + i + '.jpg';
      imgSeries.push( curImg);
      }[/code]
      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.
      Code:
       function preloadImgs() {
      	// Preload Images
      	preload_image_object = new Image();
      	for (i=0; i<=imgSeries.length; i++) {
      		 preload_image_object.src = imgSeries;
      	}
      }
      In the loop above, when i is equal to imgSeries.lengt h, which element will be indexed?

      Comment

      Working...