These don’t contain any images. They all are pure JavaScript based progress bars. They uses the JavaScript Timer Class for the delay and jQuery fading function transparency for animated effect. To add a progress bar to the page is very easy, just add include the ProgressBar class and add following code:
1 2 3 4 5 |
var bar1 = new ProgressBar("progressContainer1", 10, "progressTable", "cell1", "size"); bar1.Start(); |
First parameter is the ID of the div which will contain the progress bar. Second parameter is number of cells you want to have in progress bar. Third is the css class for outer table of the progress bar. Fourth is the the css class for each celll and fifth the the css class for the size of each cell.
Here is the code for the whole example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
<!doctype html> <html> <head> <title>Animated Progress Bar without images</title> <script src="jquery.js" type="text/javascript"></script> <style media="screen" type="text/css"> .progressTable { border: solid 1px #e1e1e1; } .size, .cell1, .cell2, .cell3 { width: 15px; height: 15px; } .cell1 { background-color: #22dd22; display: none; } .cell2 { background-color: #dd2222; display: none; } .cell3 { background-color: #2222dd; display: none; } </style> <script language="javascript"> <!-- $(document).ready(function() { var bar1 = new ProgressBar("progressContainer1", 10, "progressTable", "cell1", "size"); bar1.Start(); var bar2 = new ProgressBar("progressContainer2", 10, "progressTable", "cell2", "size"); bar2.Start(); var bar3 = new ProgressBar("progressContainer3", 10, "progressTable", "cell3", "size"); bar3.Start(); }); var ProgressBar = function(divId, cellCount, tableCss, cellCss, sizeCss) { var index = -1; var timerObj = new Timer(); this.Init = function() { var str = "<table class='" + tableCss + "' cellpadding='0' cellspacing='1'><tr>"; for(var cnt=0; cnt<cellCount; cnt++) { str += "<td class='" + sizeCss + "'><div class='" + cellCss + " " + cellCss + cnt + "'></div></td>"; } str += "</tr></table>"; $("#" + divId).append(str); timerObj.Interval = 100; timerObj.Tick = timer_tick; } this.Start = function() { this.Init(); timerObj.Start(); } function timer_tick() { //debugger; index = index + 1; index = index % cellCount; $("#" + divId + " ." + cellCss + index).fadeIn(10); $("#" + divId + " ." + cellCss + index).fadeOut(500); } } // Declaring class "Timer" var Timer = function() { // Property: Frequency of elapse event of the timer in millisecond this.Interval = 1000; // Property: Whether the timer is enable or not this.Enable = new Boolean(false); // Event: Timer tick this.Tick; // Member variable: Hold interval id of the timer var timerId = 0; // Member variable: Hold instance of this class var thisObject; // Function: Start the timer this.Start = function() { this.Enable = new Boolean(true); thisObject = this; if (thisObject.Enable) { thisObject.timerId = setInterval( function() { thisObject.Tick(); }, thisObject.Interval); } }; // Function: Stops the timer this.Stop = function() { thisObject.Enable = new Boolean(false); clearInterval(thisObject.timerId); }; }; //--> </script> </head> <body> <div id="progressContainer1"> </div> <br /> <div id="progressContainer2"> </div> <br /> <div id="progressContainer3"> </div> </body> </html> |