473,657 Members | 2,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preload next number (image) in array on a click of a mouse

Here's my problem if anyone could be so kind to help me out. I assume
it's quite easy for an experienced programmer but I'm not one of them
:)

I have a JavaScript code that:
- displays multiple images (+40) in a single image placeholder on ONE
page
- pre-loads multiple images
- on a click of a mouse changes to the next image
- on a click of a mouse changes to the previous image

PROBLEM:
1. all the images pre-load and eat up the bandwith
2. The images are not put in the browser's cache for easy loading
later on

SOLUTIONS REQUESTED:
1. that when I click "next" the next image is displayed PLUS the image
AFTER that one is loaded

2. If possible, that the images be loaded in the browsers cache.

Thank's for your time...

THE JAVASCRIPT CODE:

<script language="Javas cript">
<!--

function switchImg(from, to){
document[from].src = eval(to + ".src");
}

count = 0;
MyImages = new Array();
MyImages[0]=new Image();
MyImages[0].src='arnor00.j pg';
MyImages[1]=new Image();
MyImages[1].src='arnor01.j pg';
MyImages[2]=new Image();
MyImages[2].src='arnor02.j pg';
MyImages[3]=new Image();
MyImages[3].src='arnor03.j pg';
MyImages[4]=new Image();
MyImages[4].src='arnor04.j pg';
MyImages[5]=new Image();
MyImages[5].src='arnor05.j pg';
MyImages[6]=new Image();
MyImages[6].src='arnor06.j pg';
MyImages[7]=new Image();
MyImages[7].src='arnor07.j pg';
MyImages[8]=new Image();
MyImages[8].src='arnor08.j pg';
MyImages[9]=new Image();
MyImages[9].src='arnor09.j pg';
MyImages[10]=new Image();
MyImages[10].src='arnor10.j pg';
function loadImg(from,to ){
document[from].src = to;
}

function Next(){
if (count < MyImages.length - 1){
count = count + 1;
document.painti ngs.src = MyImages[count].src;

}
else {
count = 0;
document.painti ngs.src = MyImages[count].src;
}

}
function Back(){
if (count > 0){
count = count - 1;
document.painti ngs.src = MyImages[count].src;

}
else {
count = 4;
document.painti ngs.src = MyImages[count].src;
}

}
//-->
</script>
Jul 20 '05 #1
2 4033
as*****@finlina .is (Wonko) writes:
Here's my problem if anyone could be so kind to help me out. I assume
it's quite easy for an experienced programmer but I'm not one of them
:)

I have a JavaScript code that:
- displays multiple images (+40) in a single image placeholder on ONE
page
- pre-loads multiple images
- on a click of a mouse changes to the next image
- on a click of a mouse changes to the previous image

PROBLEM:
1. all the images pre-load and eat up the bandwith 2. The images are not put in the browser's cache for easy loading
later on
That sounds mysterious.
Prefetching/pre-loading images off-screen only serves one purpose:
to get them into the browser's cache. If they are not in the cache
later, it is either because the cache is too small, or because
they somehow told the browser that they should not be cached for long.
SOLUTIONS REQUESTED:
1. that when I click "next" the next image is displayed PLUS the image
AFTER that one is loaded

2. If possible, that the images be loaded in the browsers cache.

Some code:
---
<script type="text/javascript">

var MyImages = ['arnor00.jpg', 'arnor01.jpg', 'arnor02.jpg',
'arnor03.jpg', 'arnor04.jpg', 'arnor05.jpg',
'arnor06.jpg', 'arnor07.jpg', 'arnor08.jpg',
'arnor09.jpg', 'arnor10.jpg'];
var numURLs = MyImages.length ;
var count = 0;

var cacher = new Image();
cacher.src = MyImages[1]; // expects at least two URLs.

var prevCacher = newImage;
prevCacher.src = MyImages[numURLs - 1];

function Next(){
count = (count+1)%numUR Ls;
document.images['paintings'].src=MyImages[count];
var next = (count+1)%numUR Ls;
cacher.src=MyIm ages[next];
}

function Prev(){
count = (count-1)%numURLs;
document.images['paintings'].src=MyImages[count];
var prev = (count-1)%numURLs;
cacher.src=MyIm ages[prev];
}

</script>
---
Try it, but be warned that it is untested.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lasse Reichstein Nielsen <lr*@hotpop.com > wrote in message news:<sm******* ***@hotpop.com> ...
as*****@finlina .is (Wonko) writes:

Thanks for your help LRN...
That sounds mysterious.
Prefetching/pre-loading images off-screen only serves one purpose:
to get them into the browser's cache. If they are not in the cache
later, it is either because the cache is too small, or because
they somehow told the browser that they should not be cached for long.
Yes I agree that this is mysterious. In the code you gave me in the
"next function" it loads two image, next image and next image+1. but
it does that EVERY time, which is quite annoying. Can the hosting
provider (MediaTemple) have anything to say (configure) about that?
The page in question requires login as it's on a secure folder, does
that make a difference?
Try it, but be warned that it is untested.
/L


I did and there were minor errors in it, like you said... not tested.
Here is a functional code without errors if anyone is interested but I
couldn't verify that the preload works properly as it loads every time
on my page.

Changes:
"var PrevCacher" is out, shouldn't be neccessary if the image is
already in the cache from the "var chacher"

IF sentence added to the "back function" as it didn't display any
image if the first image in the series was loaded. now nothing
happens.

<script type="text/javascript">
<!--
var MyImages = ['arnor00.jpg', 'arnor01.jpg', 'arnor02.jpg',
'arnor03.jpg', 'arnor04.jpg', 'arnor05.jpg',
'arnor06.jpg', 'arnor07.jpg', 'arnor08.jpg',
'arnor09.jpg', 'arnor10.jpg', 'arnor11.jpg',
'arnor12.jpg', 'arnor13.jpg', 'arnor14.jpg',
'arnor15.jpg', 'arnor16.jpg', 'arnor17.jpg',
'arnor18.jpg', 'arnor19.jpg', 'arnor20.jpg',
'arnor21.jpg', 'arnor22.jpg', 'arnor23.jpg',
'arnor24.jpg', 'arnor25.jpg', 'arnor26.jpg',
'arnor27.jpg', 'arnor28.jpg', 'arnor29.jpg',
'arnor30.jpg', 'arnor31.jpg', 'arnor32.jpg',
'arnor33.jpg', 'arnor34.jpg', 'arnor35.jpg',
'arnor36.jpg', 'arnor37.jpg', 'arnor38.jpg',
'arnor39.jpg', 'arnor40.jpg',];
var numURLs = MyImages.length ;
var count = 0;

var cacher = new Image();
cacher.src = MyImages[1];

function Next(){
count = (count+1)%numUR Ls;
document.images['paintings'].src=MyImages[count];
var next = (count+1)%numUR Ls;
cacher.src=MyIm ages[next];
}

function Back(){
if (count > 0){
count = (count-1)%numURLs;
document.images['paintings'].src=MyImages[count];
var prev = (count-1)%numURLs;
cacher.src=MyIm ages[prev];
}

else {
count = 0;
document.images['paintings'].src=MyImages[count];
}
}
//-->
</script>

and the links are of course:
<a href="javascrip t:Back ()">some text or image</a>
<a href="javascrip t:Next ()">some text or image>/a>

Thanks again...
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
17247
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would do myDomElement.click and the mouse doesn't matter, but in the case of an input image element, what happens is the submitted url has something like "?x=12&y=7" appended to it (the numbers vary per mouse position on the clicked element). If you hit...
7
3648
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;
3
1728
by: Bob | last post by:
I usually use some "pre-load" code in my pages to preload graphics that will be swapped. But, I'm thinking that rather than the long, repetitive, once, for each graphic hardcoded stuff like this: var bb_off = new Image(); bb_off.src = "images/bb_off.jpg"; ....that I could have an array where I just listed the names of the graphics, a loop, and code in the loop that cycles through each entry in the array to create and pre-load the "on"...
1
1912
by: Harod Ruthgar | last post by:
var image = new Image(); image.src="pathToTheFile"; The above code is called 25 times (with different pathToTheFile) within a loop. I manually checked the cache directory and not all images are cached, sometimes it's only 3, sometimes 4, etc, and mostly only the last few images within the loop.
15
7046
by: Tony Gahlinger | last post by:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7) to do some client-side image processing. I want to capture the sequence of coordinates a user clicks on in xxx.jpg in the following html <a href="#"><IMG SRC="xxx.jpg" ISMAP></a> and save these to a file for later handling. The coordinates appear on the bottom left of the window as I move the mouse, so I know they're being passed around somehow, but I haven't...
2
3379
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...
4
1723
by: shapper | last post by:
Hello, I think to preload an image I should us something like: img = new Image(); img.src = 'images/img.jpg'; Could someone tell me how to create a loop which would preload a list of images? Something like:
2
1341
by: matt9807 | last post by:
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? imgSeries = new Array(); curImg = ''; function loadkill() { document.getElementById('loadingtxt').style.display = "none"; document.getElementById('imgone').src = imgSeries; document.getElementById('imgtwo').src = imgSeries; }
3
1886
by: Revathi Balakrishnan | last post by:
Hi i have the used the below code to switch the button image on mouseover and mouseout. <html:button property="Button" value="Display" styleClass="displaybutton" onmouseover="this.className='displaybutton displaybuttonover'" onmouseout="this.className= 'displaybutton'"/> CSS definition of displaybutton and displaybuttonover is shown below.
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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();...
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
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.