5,693,062 members and growing! (17,798 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Intermediate License: The Code Project Open License (CPOL)

Javascript Progress Bar

By Lazmi ofer

how to create a manual and automatic progress bar using JavaScript
Javascript, Windows, .NET, Ajax, Dev

Posted: 11 Oct 2008
Updated: 11 Oct 2008
Views: 5,314
Bookmarked: 25 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
12 votes for this Article.
Popularity: 3.92 Rating: 3.63 out of 5
1 vote, 8.3%
1
1 vote, 8.3%
2
0 votes, 0.0%
3
3 votes, 25.0%
4
7 votes, 58.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article



If you look for a pretty javascript progress bar to use as a printing progress bar or any other use and you need it to work manually and / or automaticlly the read this article.

Introduction

I needed to build a custom progress bar that could be progress automaticly and manualy by code.
This progress bar can be helfull as a printing progress bar or any other usfull use.
the progerss bar get the maxStep counetr and print the right number of bullets per step.
max bullets per progress bar determind by the size of the background image and can be change in javascript file by the parameter numOfBullets.

The progress bar has two operation mode:

1. Manual - by calling NextStep method.
2. Automatic - activate NextStep method automaticlly every configured interval.

The progress bar contain some usfull methods:

1. (constructor)(maxStep) - get the maxStep parameter (default is 1)
2. SetProgressBarContainer(progressBarContainer) - get the progress bar DIV container. where all the bullets will be place.
3. SetMaxStep(maxStep) - get the maxStep parameter of the progress. (if we need to change the maxStep in after initiance).
4. NextStep() - show the next bullets for the next step.
5. Auto() - start automatic progressing of the pgrogress bar bullets.
6. Stop() - stop the automatic progress bar.
7. Reset() - reset parameters.


class global parameters :

1. numOfBullets - the number of bullets thet can be entered in the progress bar backgound.
2. timeInterval - the time interval in seconds to move nextStep to use in auto mode.

Background

The javascript file contain a progress bar class that create using the open source of Prototype JavaScript Framework .
Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.

Using the code - Embedding and including

First include the prototype js file and the progress bar js file.

 		
<script type="text/javascript" language="javascript" src="Js/prototype-1.6.0.2.js"></script>
<script type="text/javascript" language="javascript" src="Js/ProgressBar.js"></script>

Place in html page the progress bar div and name it progressBarContainer. In the body tag set the onload method.
<body  önload="onload()">
and the implemtation is:
//handle of the maxStep textbox
var maxStep;

function onload()
{
	//handle of the maxStep textbox
	maxStep = $("maxStep");
	//get progressBar container div
	var progressBarContainer = $("progressBarContainer");
	//create new instance of progressBar class and pass the number of max step
	progressBar = new ProgressBarClass(maxStep.value);
	//set progressBar container div
	progressBar.SetProgressBarContainer(progressBarContainer);
	//set callback function to be notify when step changed
	progressBar.OnStepChange = OnStepChange;	
}
Create a buttons for start, stop, reset,next the progress bar and attach them the next methods.

function Auto()
{
	progressBar.Auto ();
}
function Next()
{
	progressBar.NextStep ();
}
function Stop()
{
	progressBar.Stop ();
}
function Reset()
{
	progressBar.Reset ();
	$("pages").innerHTML = "0 pages printed";
}
function SetMaxStep()
{	
	progressBar.SetMaxStep(maxStep.value);
}
There progress bar class also can get a delegate to a user method which activate on any stepChange and contain the current step

//set callback function to be notify when step changed
progressBar.OnStepChange = OnStepChange;

function OnStepChange(currentStep)
{	
	$("pages").innerHTML = currentStep + " pages printed";
}

Thats it.
I hope that you find it helfull like me.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Lazmi ofer



Occupation: Software Developer
Location: Israel Israel

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Oct 2008
Editor:
Copyright 2008 by Lazmi ofer
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project