473,414 Members | 1,936 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,414 software developers and data experts.

Advice on Preloading Images.

Hi folks,

I am using the following code for mouse over (roll-overs) in my XHTML code.

<a onmouseover="document.getElementById('sitemap').sr c =
'../images/buttons/sitemap_mo.jpg';"
onmouseout="document.getElementById('sitemap').src =
'../images/buttons/sitemap.jpg';"
href="../sitemap.htm" border="0">
<img id='sitemap' src="../images/buttons/sitemap.jpg" border="0" alt="Site
Map"/></a>

However, I have not preloaded the images, and wonder if someone could help
by suggesting suitable code to preload the images.

Regards,
C.B.
Sep 26 '06 #1
1 1367

"Cerebral Believer" <no**********@hadenoughalready.comwrote in message
news:lk*******************@newsfe2-gui.ntli.net...
Hi folks,

I am using the following code for mouse over (roll-overs) in my XHTML
code.

<a onmouseover="document.getElementById('sitemap').sr c =
'../images/buttons/sitemap_mo.jpg';"
onmouseout="document.getElementById('sitemap').src =
'../images/buttons/sitemap.jpg';"
href="../sitemap.htm" border="0">
<img id='sitemap' src="../images/buttons/sitemap.jpg" border="0" alt="Site
Map"/></a>

However, I have not preloaded the images, and wonder if someone could help
by suggesting suitable code to preload the images.

Regards,
C.B.
I was thinking of using this code in the head section

<script Language="JavaScript" typr="text/javascript">

image1 = new Image();
image1.src = "images/buttons/home.jpg";
image2 = new Image();
image2.src = "images/buttons/home_mo.jpg";
image3 = new Image();
image3.src = "images/buttons/blog.jpg";
image4 = new Image();
image4.src = "images/buttons/blog_mo.jpg";
image5 = new Image();
image5.src = "images/buttons/reviews.jpg";
image6 = new Image();
image6.src = "images/buttons/reviews_mo.jpg";

image7 = new Image(); image7.src = "images/buttons/music.jpg"; image8 = new
Image(); image8.src = "images/buttons/nusic_mo.jpg"; image9 = new Image();
image9.src = "images/buttons/links.jpg"; image10 = new Image(); image10.src
= "images/buttons/links_mo.jpg"; image11 = new Image(); image11.src =
"images/buttons/contact.jpg"; image12 = new Image(); image12.src =
"images/buttons/contact_mo.jpg"; image13 = new Image(); image13.src =
"images/buttons/sitemap.jpg"; image14 = new Image(); image14.src =
"images/buttons/sitemap_mo.jpg";

</script>

Would this be suitable code to preload the images for more efficient loading
for my HTML code originally posted?

I wonder if the JavaScript preload statements must all be on a new line, or
if they can just be one one line separated by ";".

Regards,
C.B.
Sep 26 '06 #2

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

Similar topics

22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
2
by: Julie | last post by:
Hi, I'm trying to change images on a website without reloading the whole page and use the following code to preload the images: var preloadFlag = false; function preloadImages() { if...
6
by: michaaal | last post by:
Is this the correct way to preload an image...? Var Image1 = new Image() ....And then when I'm ready to use the image I can do this...? Button1.src=Image1.src ....Or am I just telling...
2
by: windandwaves | last post by:
Hi Gurus Preloading images has got to be JS 101. However, it does not seem to be working. Here is the function that I am using. I added the alerts to make sure it is working and all the right...
40
by: Geoff Cox | last post by:
Hello, I am still having problems - apologies if the answer is in previous postings! I now have, in the header, <sctipt> var myimages=new Array();
2
by: sachaburnett | last post by:
Hi everyone! I'm new to Javascript and am finding so much useful information on this group, so thanks to you all! I have a question about preloading images for onmouseover/out effects and...
7
by: Inny | last post by:
Hello again, Im using the code below in a child page (popup), the images are called from the parent page. When the changer is running, the child page goes white between images. I realise this is...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
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?
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...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.