Solved

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

Posted on 2006-11-13
5
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

734 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