473,785 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 1348
pronerd
392 Recognized Expert Contributor
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 New Member
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.lengt h, 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
3659
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 this: function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length;
9
1810
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 image is linkable to a popup window displaying the same image only larger. Can this even be done? If so any ideas? Thanks in advance. <HEAD>
2
3389
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 to 50+mb; and, normally completes in less than 1 minute without preload (using DSL). The preload terminates after 6 or 7 images and seems to time-out in the middle of an image. A reload will download a few more, etc. I have used the <body...
1
2271
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? http://pfastre.no-ip.com/arg/ http://pfastre.no-ip.com/lunatis/ http://pfastre.no-ip.com/gsm/ ....
14
3136
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 (I don't have IE, but I have my suspicions that wouldn't work either). I'd like to use CSS to put some boxes down the middle of a page. The page is intended to be fluid, but the boxes all need to be the same width, which can be variable...
7
9109
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 http://www.saintrays.net/experiment2.html http://www.saintrays.net/experiment3.html View the source of each page to see the relevant javascript. All three
4
1797
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 float, then using absolute positioning (and z-index) to display the image over the second float. The CSS for the thumbnails is from "Web Accessibility At C-net.us" by K Chayka (http://accessat.c-net.us/test/gallery2.html). The CSS to display the...
1
3407
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 ( for ex. http://www.agathamoon.com/gallery_48_eng.htm ) using explorer or firefox it works, with safari it doesn't! :( The idea is to have the word "loading" appearing while going from an image to another.
1
2378
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
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.