Solved

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

Posted on 2006-11-13
5
346 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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…
Suggested Courses

631 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