Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now