Solved

Show loading image in a <div> until the content or image is loaded.

Posted on 2006-11-13
5
342 Views
Last Modified: 2010-05-18
Hey all,
Is there a simple script you could help me with to display a loading image in a <div> until the content or image is loaded?

Thanks!
0
Comment
Question by:wglenn01
5 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 168 total points
ID: 17935949
Check this out:

<html>
      <head>
            <title>Script Demo</title>
            <script language="JavaScript">
                  function changeStatus(){
                        document.getElementById('imgStatus').innerHTML="Image Loaded Successfully!!!"
                  }
            </script>
      </head>
<body>
      <img src="http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif" onload='changeStatus();'>
      <div id="imgStatus">Loading Image</div>
</body>
</html>
0
 
LVL 6

Assisted Solution

by:aescnt
aescnt earned 166 total points
ID: 17936032
By the way, a cute fix to do this is if you have an image in a div like so:

<div><img src="image.jpg"></div>

You can set the div's background-image (with CSS) to a loading bar. That way, when the image isn't fully loaded, the loading bar will show up, but once the image is loaded it will cover the bar. :)
0
 
LVL 6

Assisted Solution

by:badalpatel
badalpatel earned 166 total points
ID: 17936120
lets try this modified code of gops1
Check this out:

<html>
     <head>
          <title>Script Demo</title>
          <script language="JavaScript">
               function changeStatus(){
                    document.getElementById('imgStatus').visibility='hidden';
               }
          </script>
     </head>
<body>
     <img src="http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif" onload='changeStatus();'>
     <div id="imgStatus">Loading Image</div>
</body>
</html>
 
 
 
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

825 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