Solved

use onLoad to hide/show images

Posted on 2001-08-06
5
497 Views
Last Modified: 2008-03-04
Hello,

I have an intranet site with GIF images which load slowly and at different rates.  I am looking for someone who can give me usable code which preloads images into cashe (possibly using the onLoad function and looping until every image is loaded and then displaying the images all at once.)  

I use the <DIV> tag to position my images and can set my images to be hidden by default instead of visible.   I am a novice web developer with no javascript experience so please keep everything simple.

Thank you!

0
Comment
Question by:stevenshl
5 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6356011
Is it an IE only intranet?

If so you can use the following.

Add this to the <head>-section:
<style type='text/css'>
IMG{visibility:hidden;}
</style>

Then load the usual way (no changes needed in your current code). And then add the folowing script (also in the Head-section):
<script>
function document_onload()
{
   for(i=0;i<document.images.length;i++) document.images[i].style.visibility="visible";
}
window.onload=document_onload;
</script>



If you want a different approach, just ask. me or someone else will be able to help you out.

regards,
CJ
0
 
LVL 9

Accepted Solution

by:
nimaig earned 100 total points
ID: 6356187
Try this. Works in both IE and netscape

<html>
<script language="JavaScript">
<!--
     var imgCount = 9;
     var imgLoaded = 0;
     function dispDIV(){
          imgLoaded++;
          if(imgLoaded >= imgCount){
               if(document.all){
                    window.divImg.style.visibility="visible";
               }else if(document.layers){
                    document.divImg.visibility="show";
               }
          }
     }
//-->
</script>
<body>
<form name=myform>
</form>
<DIV name="divImg" id="divImg" style="position:absolute;visibility:hidden">
     <img src="http://otnxchange.experts-exchange.com/images/otn_logo_75x44_xp.gif" onLoad="javascript:dispDIV()">
     <img src="http://www.onjava.com/images/onjava/onjava_logo.jpg" onLoad="javascript:dispDIV()">
     <img src="http://careers.onjava.com/graphics/complogo_thomson.gif" onLoad="javascript:dispDIV()">
     <img src="http://m.doubleclick.net/viewad/567037-468-6to4.gif" onLoad="javascript:dispDIV()">
     <img src="http://m.doubleclick.net/viewad/538206-125-essentialjs2.gif" onLoad="javascript:dispDIV()">
     <img src="http://servedby.advertising.com/mnum=0000018953/logs=0/bins=1/site=0000034004/bnum=34004" onLoad="javascript:dispDIV()">
     <img src="http://otnxchange.experts-exchange.com/images/otn.gif" onLoad="javascript:dispDIV()">
     <img src="http://m.doubleclick.net/viewad/620465-altoweb_120x480_rev2__060501aaaa.gif" onLoad="javascript:dispDIV()">
     <img src="http://ad.doubleclick.net/557907/sgp2q01_336x280_WS_DEV_v_r3_c2.jpg" onLoad="javascript:dispDIV()">
</DIV>

</body>
</html>

0
 

Author Comment

by:stevenshl
ID: 6356646
Our intranet is used by IE and Netscape... we try to keep users current  -  within the last two revisions of both.
0
 
LVL 4

Expert Comment

by:ravi_raj123
ID: 6359165
HI,

<html>
<head>
<script language="JavaScript">
<!--
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; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" background="images/Celebrations.jpg" onLoad="MM_preloadImages('images/pic0.jpg','images/pic1.jpg','images/pic2.jpg','images/pic3.jpg','images/pic4.jpg','images/pic5.jpg')">
</body>
</html>

Hope this is pretty clear to you.
Hope this helps you.
Good Luck...:)
0
 

Author Comment

by:stevenshl
ID: 6361277
Thanks for your help... this code definitely got me going in the right direction.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question