Solved

load image background

Posted on 2006-11-06
6
245 Views
Last Modified: 2010-04-09
hello,
I have a web page that has 175 images
150x200 and they are in blocks of
5 row by 6 columns
when I go the page I see the images loading
and I would to have a backgound under the image
before it loads! the bg image will say (loading image)
so my surfers now that those images are still loading!
how can I do this?
0
Comment
Question by:Sabrin
6 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 17887963
Make a default image titled "Loading Image" and place them whereever the images are to be shown. I mean by default when the click the image, this is going to be your default image. Once done, get all your images into an array and pupulate them using javascript, one by one.
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 17890282
Here's one way to do it, i just pulled a loading image from google and a rather large file so the page takes a while to load.  If you also want the loading image to be displayed over the other images, change the  z-index:-1; to something high like 10, 20 or even 100.

The height:100% might be an IE thing, i think ive had trouble with FF, you might need to grab the screen rez and dynamically do it.

Basically the:
var imageLoader = new Image();
imageLoader.src = "http://"

forces the file to be loaded, if you put it in the normal src=, it might wait for the others to finish or go down the queue, and if you put it in the onload, you have to wait for the other images to load first before it will be called.


<html>
<body onload="HideThatThing()">
      <img id="TheImage" style="position:absolute; top:0px; left:0px; width:100%; height:100%; z-index:-1;">
      <script>
            theImageToChange = document.getElementById("TheImage");
            var imageLoader = new Image();
            imageLoader.src = "http://dlis.dos.state.fl.us/bld/flyp/2002/images/loading.gif";
            theImageToChange.src = imageLoader.src;

            function HideThatThing()
            {
                  document.getElementById("TheImage").style.display = "none";
            }

      </script>
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <br />
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <br />
    <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <img width=150 src="http://gallery.hd.org/_exhibits/natural-science/_more2002/_more01/fish-carp-Koi-Nishikigoi-in-Japanese-Garden-Balboa-Park-San-Diego-California-2-MB.jpg">
      <br />

</body>
</html>
0
 

Author Comment

by:Sabrin
ID: 17890641
I mean the images are 150x200 and the loading.gif has to be 150x200 under the images
so it goes loading from top to bottom and if you scroll all they way to the bottom while
the page is still loading you can see the loading.gif
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 17896555
Then do what gops1's said.

Have one image (like the loading one i used) and use that same src= for all your images on the site.

Then, run through a loop over an array of pairs (id,src).  Then load the src into a javascript Image(), when its loaded, change the src of the (id,) to the (,src). Eventually it will go through the loop and walla!

Seem complicated? Break it down.


1)  Change all you images to eg: loading.gif

2) Make an array-
http://www.w3schools.com/js/tryit.asp?filename=tryjs_array

Here's how they work:
http://www.javascriptkit.com/jsref/arrays.shtml

Here's how to loop through it:
http://www.utexas.edu/courses/lis385t/jsarray.html (view the source)

3) Javascript pair (id,src)
http://www.sitepoint.com/article/oriented-programming-1/2

The difference between a pair and these examples, is that a paid on has 2 things, these examples can have 10, 20, etc.  You could make one with 3 if you need to add something later on.

4) Load images in javascript
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21990897.html

5)
"change the src of the (id,) "
You'll needed to of mastered 3), and just do what i did in my first post.  I would make a function that takes an id and a src, and then changes the image.  Makes the code cleaner.

6) put all this stuff in a loop
http://www.w3schools.com/js/js_looping.asp




So 6 simple steps to play with, my advice would be to create a seperate page for each step and just get a loop working, just get a pair working.  THEN you add it back into your webpage, makes life alot easier for yourself.


You'll notice a few links from w3schools, a very recomended site, and if your stuck google for examples, break them down and find what you need.
0
 
LVL 2

Accepted Solution

by:
peeldog earned 500 total points
ID: 17903093
Maybe you could use stylesheets to set the background of a cell to an image...

I tried this and it seemed to work:

<HTML>
<BODY>
<TABLE>
<TR><TD STYLE="background:url('http://www.mocap.ca/images/rig.jpg')">whoo</TD></TR>
</TABLE>
</BODY>
</HTML>

Replace whoo with an <IMG> tag and make sure the cell is smaller than your image (maybe set its height and width to 1).
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 17903732
Great idea peeldog, only problem i can see is that css backgrounds dont seem to like scaling, but if all your images are going to be the same size and stay that way it should work.  Alot easier though.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send Mail Via SMTP Replacement/Rework 11 60
HTML CSS 7 38
Bootstrap Columns not Side-by-Side 3 36
Put shading on half of picture 8 24
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now