Connecting Tech Pros Worldwide Help | Site Map

Extremely Simple Progress Bar

  #1  
Old November 23rd, 2007, 06:10 PM
Death Slaught's Avatar
Site Addict
 
Join Date: Aug 2007
Location: Tennessee
Posts: 952
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.   function progress() {
  5.    if (document.images["bar"].width < 400) {
  6.     document.images["bar"].width += 5;
  7.     document.images["bar"].height = 5;
  8.    } else {
  9.     clearInterval(ID);
  10.    }
  11.   }
  12.  
  13. var ID;
  14. window.onload = function() {
  15.   ID = setInterval("progress();", 500);
  16. }
  17. </script>
  18. </head>
  19. <body>
  20. <img src="black.gif" name="bar" />
  21. </body>
  22. </html>
black.gif is an extremely small square I made in paint.

- Death



  #2  
Old November 27th, 2007, 11:08 AM
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,102

re: Extremely Simple Progress Bar


hi ...

good work very simple ... yes :) ... have a look at the following example that uses no image at all ... simply div/css, may be that could be used as an alternative pure dhtml-solution:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.         var prg_width = 200;
  5.  
  6.         function progress() {
  7.             var node = document.getElementById('progress');
  8.             var w    = node.style.width.match(/\d+/);
  9.  
  10.             if (w == prg_width) {
  11.                 w = 0;
  12.             }
  13.  
  14.             node.style.width = parseInt(w) + 5 + 'px';
  15.         }
  16.  
  17.         </script>
  18.     </head>
  19.  
  20.     <body onload="var progress_run_id = setInterval(progress, 250);">
  21.  
  22.         <div style="border: 1px solid black; width:200px; height:5px;">
  23.             <div id="progress" style="height:5px; width:0px; background-color:red;"/>
  24.         </div>
  25.  
  26.     </body>
  27. </html>
  28.  
kind regards
  #3  
Old November 27th, 2007, 03:06 PM
Death Slaught's Avatar
Site Addict
 
Join Date: Aug 2007
Location: Tennessee
Posts: 952

re: Extremely Simple Progress Bar


Nice I never thought of doing it like that, I was going to add on to it making it more complecated when I got time.

Thanks, Death
  #4  
Old November 30th, 2007, 01:58 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,521

re: Extremely Simple Progress Bar


Quote:
Originally Posted by Death Slaught
Nice I never thought of doing it like that, I was going to add on to it making it more complecated when I got time.
You could show the current percentage complete as the next step.

If this could be linked to some activity rather than just progress at regular intervals, it might have more use rather than just replace an animated loading indicator image.
  #5  
Old December 1st, 2007, 06:27 PM
Death Slaught's Avatar
Site Addict
 
Join Date: Aug 2007
Location: Tennessee
Posts: 952

re: Extremely Simple Progress Bar


Yeah I planned on doing just that. The problem is, my free time is at an all time low. I have an extra credit site i'm working on, a site for a friends club, and high school to deal with :). So the second I get some free time, hopefully i'll have some in my first period, biology=boredom.

- Death
  #6  
Old September 27th, 2008, 01:08 AM
Newbie
 
Join Date: Sep 2008
Posts: 4

re: Extremely Simple Progress Bar


Quote:
Originally Posted by gits
hi ...

good work very simple ... yes :) ... have a look at the following example that uses no image at all ... simply div/css, may be that could be used as an alternative pure dhtml-solution:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.         var prg_width = 200;
  5.  
  6.         function progress() {
  7.             var node = document.getElementById('progress');
  8.             var w    = node.style.width.match(/\d+/);
  9.  
  10.             if (w == prg_width) {
  11.                 w = 0;
  12.             }
  13.  
  14.             node.style.width = parseInt(w) + 5 + 'px';
  15.         }
  16.  
  17.         </script>
  18.     </head>
  19.  
  20.     <body onload="var progress_run_id = setInterval(progress, 250);">
  21.  
  22.         <div style="border: 1px solid black; width:200px; height:5px;">
  23.             <div id="progress" style="height:5px; width:0px; background-color:red;"/>
  24.         </div>
  25.  
  26.     </body>
  27. </html>
  28.  
kind regards
Really simple and useful progress bar.
BTW, how to detect the software image in jar or zip on completing download/upload so the progress bar disappears after loading.
Thanks.

Hannie
  #7  
Old September 29th, 2008, 04:40 PM
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,102

re: Extremely Simple Progress Bar


Quote:
Originally Posted by hannie
Really simple and useful progress bar.
BTW, how to detect the software image in jar or zip on completing download/upload so the progress bar disappears after loading.
Thanks.

Hannie
could you please explain in more detail what you want to do? typically you should wrap the shown code in a function and call it to start the progress-bar when you start a XMLHttpRequest. When the request is ready you just have to clear the interval and/or hide the progress-bar and display the received result in the request-object's final callback ...

kind regards
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms Burns answers 2 November 15th, 2005 06:44 PM