473,382 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1320
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

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

Similar topics

7
by: MALdito | last post by:
hi everybody let me say right from the start .. I´m not a coder ... "just" a designer! that said .. here is my question: I´m using dreamweaver´s built in preloader for a menu. it looks like...
9
by: Flynn | last post by:
My understanding of javascript is very limited. Could some one help me out. I found this code for an image gallery viewer. It works fine on my site, but I'd like to modify it so that the mainpic...
2
by: Albert Spencil | last post by:
I have tried several preload scripts found here; plus, some of my own. The only thing that works is the unsophisticated loading of those tiny images. The download consist of 100+ images amounting...
1
by: Peter Fastré | last post by:
Hello The javascript preload function I always used, is causing problems with the latest version of gecko-browsers. Never had any problems with it though. Maybe there's something wrong? ...
14
by: Eric Lindsay | last post by:
I've seen a page using display, and especially display table that did some neat things with boxes, but basically it only worked with Mozilla browsers. Fell over fairly badly with Opera and Safari...
7
by: cjl | last post by:
OK: I am really scratching my head over a preload / image swapping problem, so I started conducting experiments: http://www.saintrays.net/experiment1.html...
4
by: RE Kochanski | last post by:
I have attempted to use the CSS techniques from two or three sites to create a CSS only image gallery. I am muddling the affair by placing the thumbnails in one float, the page text in another...
1
by: agatha.life | last post by:
I did a javascript for the loading of images (I didn't want to have the images loaded in "on loading" because they are too many). The website is for a model and if you look at the codeof pages (...
1
by: shapper | last post by:
Hello, Is there a way to preload a few images of a page using only CSS? If yes, how can I do it, and should I use CSS or Javascript to do this? Thanks, Miguel
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.