|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
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
Introduction
I needed to build a custom progress bar that could be progress automaticly and manualy by code. Background
The javascript file contain a progress bar class that create using the open source of Prototype JavaScript Framework . Using the code - Embedding and includingFirst 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.
|
||||||||||||||||||||||