472,989 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 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 1306
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
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.