├── ProBar.js ├── index.html └── readme.md /ProBar.js: -------------------------------------------------------------------------------- 1 | (function (root) { 2 | "use strict"; 3 | 4 | //////////////////// 5 | // all functions. // 6 | //////////////////// 7 | // first class instantiation. 8 | function proBar(options){ 9 | 10 | this.height = 5; // 5px by default. 11 | this.colorBar = "#2a2a2a"; 12 | this.wrapper_color = "#ecf0f1"; 13 | this.speedAnimation = 0.3; // in seconds 14 | this.wrapper = "body"; // default value of appending. 15 | this.finishAnimation = true; 16 | this.classNameBar = "progressBar"; // default. 17 | this.wrapperId = "wrapper-progressBar"; // default. 18 | this.rounded = { // by default All is on Zero. 19 | topLeft : 0, 20 | topRight : 0, 21 | bottomLeft : 0, 22 | bottomRight : 0 23 | }; 24 | this.roundedInternal = { // by default All is on Zero. 25 | topLeft : 0, 26 | topRight : 0, 27 | bottomLeft : 0, 28 | bottomRight : 0 29 | } 30 | 31 | this.options = options || {}; 32 | 33 | 34 | if(this.options.color) { this.colorBar = this.options.color } 35 | if(this.options.height) { 36 | this.height = this.options.height; 37 | } 38 | if(this.options.bgColor) { this.wrapper_color = this.options.bgColor } 39 | if(this.options.speed) { this.speedAnimation = this.options.speed } 40 | if(this.options.wrapper) { this.wrapper = this.options.wrapper } 41 | if(this.options.finishAnimation == false) { this.finishAnimation = this.options.finishAnimation;} 42 | if(this.options.classNameBar) { this.classNameBar = this.options.classNameBar } 43 | if(this.options.wrapperId) { this.wrapperId = this.options.wrapperId } 44 | if(this.options.rounded) { 45 | this.rounded.topLeft = this.options.rounded.topLeft || 0; 46 | this.rounded.topRight = this.options.rounded.topRight || 0; 47 | this.rounded.bottomLeft = this.options.rounded.bottomLeft || 0; 48 | this.rounded.bottomRight = this.options.rounded.bottomRight || 0; 49 | } 50 | if(this.options.roundedInternal) { 51 | this.roundedInternal.topLeft = this.options.roundedInternal.topLeft || 0; 52 | this.roundedInternal.topRight = this.options.roundedInternal.topRight || 0; 53 | this.roundedInternal.bottomLeft = this.options.roundedInternal.bottomLeft || 0; 54 | this.roundedInternal.bottomRight = this.options.roundedInternal.bottomRight || 0; 55 | } 56 | 57 | // create Bar. 58 | createBar( 59 | this.wrapper, 60 | this.classNameBar, 61 | this.height, 62 | this.colorBar, 63 | this.wrapperId, 64 | this.wrapper_color, 65 | this.rounded, 66 | this.roundedInternal 67 | ); 68 | 69 | // move the bar 70 | this.move = (percent) => { 71 | 72 | $("."+this.classNameBar).css({ 73 | width: percent+"%", 74 | transition : "width "+this.speedAnimation+"s" 75 | }); 76 | 77 | // if animation is true, reInitializate Probar. 78 | if(this.finishAnimation == true) { 79 | $("#"+this.wrapperId).css({ 80 | "height": this.height+"px" 81 | }); 82 | } 83 | 84 | // verify if is 100% 85 | setTimeout(() => { 86 | if(percent == 100 && this.finishAnimation == true) { 87 | console.log("je vais faire l'animation bro"); 88 | $("#"+this.wrapperId).css({ 89 | "height": "0px", 90 | "transition" : "all 0.3s" 91 | }); 92 | // reset bar to zero. 93 | $("."+this.classNameBar).css({ 94 | width: "0%" 95 | }); 96 | } 97 | },this.speedAnimation * 1000); 98 | } 99 | var setSpeed = (speed) => { 100 | this.speedAnimation = speed; 101 | } 102 | var setColor = (color) => { 103 | this.colorBar = color; 104 | $("."+this.classNameBar).css({ 105 | "background-color" : this.colorBar 106 | }); 107 | } 108 | var setWrapperColor = (color) => { 109 | this.wrapper_color = color; 110 | $("#"+this.wrapperId).css({ 111 | "background-color" : this.wrapper_color 112 | }); 113 | } 114 | var setFinishAnimation = (boolean) => { 115 | this.finishAnimation = boolean; 116 | } 117 | var setRounded = (topLeft = 0,topRight = 0,bottomLeft = 0,bottomRight = 0) => { 118 | 119 | this.rounded.topLeft = topLeft || 0; 120 | this.rounded.topRight = topRight || 0; 121 | this.rounded.bottomLeft = bottomLeft || 0; 122 | this.rounded.bottomRight = bottomRight || 0; 123 | 124 | $("#"+this.wrapperId).css({ 125 | "border-top-left-radius" : this.rounded.topLeft+'px', 126 | "border-top-right-radius" : this.rounded.topRight+'px', 127 | "border-bottom-left-radius" : this.rounded.bottomLeft+'px', 128 | "border-bottom-right-radius" : this.rounded.bottomRight+'px' 129 | }); 130 | } 131 | var setRoundedInternal = (topLeft = 0,topRight = 0,bottomLeft = 0,bottomRight = 0) => { 132 | 133 | this.roundedInternal.topLeft = topLeft || 0; 134 | this.roundedInternal.topRight = topRight || 0; 135 | this.roundedInternal.bottomLeft = bottomLeft || 0; 136 | this.roundedInternal.bottomRight = bottomRight || 0; 137 | 138 | $("."+this.classNameBar).css({ 139 | "border-top-left-radius" : this.roundedInternal.topLeft+'px', 140 | "border-top-right-radius" : this.roundedInternal.topRight+'px', 141 | "border-bottom-left-radius" : this.roundedInternal.bottomLeft+'px', 142 | "border-bottom-right-radius" : this.roundedInternal.bottomRight+'px' 143 | }); 144 | } 145 | var setHeight = (height = 5) => { 146 | this.height = height; 147 | $("#"+this.wrapperId).css({ 148 | "height" : this.height+'px' 149 | }); 150 | $("."+this.classNameBar).css({ 151 | "height" : this.height+'px' 152 | }); 153 | } 154 | 155 | let ProBar = { 156 | setSpeed, 157 | setHeight, 158 | setColor, 159 | setWrapperColor, 160 | setFinishAnimation, 161 | setRounded, 162 | setRoundedInternal, 163 | goto: (percent,time = null) => { 164 | if(time != null) {setSpeed(time)} 165 | this.move(percent); 166 | } 167 | }; 168 | 169 | return ProBar; 170 | } 171 | 172 | 173 | var createBar = ( element,classNameBar,height,colorBar,wrapperId,wrapper_color,rounded,roundedInternal ) => { 174 | console.log("la hauteur est de "+height); 175 | var Css = ` 176 | .${classNameBar} { 177 | width : 0px; 178 | height : ${height}px; 179 | background-color: ${colorBar}; 180 | border-radius : ${roundedInternal.topLeft}px ${roundedInternal.topRight}px ${roundedInternal.bottomLeft}px ${roundedInternal.bottomRight}px; 181 | } 182 | #${wrapperId} { 183 | width : 100%; 184 | height : ${height}px; 185 | background-color : ${wrapper_color}; 186 | overflow: hidden; 187 | border-radius : ${rounded.topLeft}px ${rounded.topRight}px ${rounded.bottomLeft}px ${rounded.bottomRight}px; 188 | } 189 | `; 190 | 191 | var htmlBar = `
`; 192 | $(element).prepend(htmlBar); 193 | $("head").append(` 194 | 197 | `); 198 | } 199 | 200 | if (window.jQuery) { 201 | console.log("JQuery is installed !"); 202 | root.ProBar = proBar; 203 | } else { 204 | // jQuery is not loaded 205 | console.warn("No Jquery - add it as CDN"); 206 | return false; 207 | } 208 | }(this)); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ProBar JS- A Custom ProgressBar for your website. 6 | 7 | 8 | 9 | 10 | 11 | 45 | 46 | 47 | 48 | 49 | 50 | 56 | 57 | 58 | 59 |
60 |
61 |
62 |

Probar

63 |
64 |
65 |
A progress bar with multiple options.
66 |

for all the people who do not have the time.. 😜

67 |
68 |
69 |
70 |
71 | 74 |
75 |
76 | 79 |
80 |
81 | 84 |
85 |
86 |
87 |
88 |
89 |
90 |

91 | Customize your Probar 92 |

93 |
94 |
95 |
Configuration with time ( in seconds ) :
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | 106 |
107 |
108 | 111 |
112 |
113 | 116 |
117 |
118 | 121 |
122 |
123 | 124 | 125 | 126 |
127 |
128 |
Configuration colors :
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | 139 |
140 |
141 | 144 |
145 |
146 | 149 |
150 |
151 | 152 |
153 |
154 |
Configure a Height of Probar :
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 | 165 |
166 |
167 | 170 |
171 |
172 | 175 |
176 |
177 | 180 |
181 |
182 | 183 | 184 | 185 |
186 |
187 |
Configuration With rounded Corners :
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 | 198 |
199 |
200 | 203 |
204 |
205 | 208 |
209 |
210 | 213 |
214 |
215 | 216 | 217 | 218 |
219 |
220 |
Configuration With rounded Corners ( Internal ) :
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 | 231 |
232 |
233 | 236 |
237 |
238 | 241 |
242 |
243 | 246 |
247 |
248 | 249 | 250 |
251 |
252 |

253 | Exemple : 254 |

255 |
256 |
257 |
258 | 						
259 | // options
260 | var options = {
261 |     color   : "#09b1ba", // color of the Progress bar. 
262 |     bgColor : "#efefef", // color background of the Progress bar
263 |     speed   : 0.3, // speed of animation. ( unit in secondes )
264 |     wrapper : ".wrapper", // the wrapper who append ProBar. if use class => ".class" ,if use id => "#id" 
265 |     finishAnimation : false, // default "true", this option give you a animation at the end "100%".
266 |     classNameBar : "proBar", // change a class to a custom class ( for Css ).
267 |     wrapperId : "wrapperProBar", // change a wrapper id for a custom Css.
268 |     height:10, // give a height to Probar.
269 |     rounded : { // use it to round Corners of Probar.
270 |     	topLeft : 25,
271 |     	topRight : 25,
272 |     	bottomLeft : 25,
273 |     	bottomRight : 25 
274 |     },
275 |     roundedInternal : { // use it to round Corners of Probar Internaly.
276 |     	topLeft : 25,
277 |     	topRight : 25,
278 |     	bottomLeft : 25,
279 |     	bottomRight : 25 
280 |     }
281 | };
282 | 
283 | // instantiate
284 | var probar = new ProBar(options);
285 | 
286 | // use it.
287 | probar.goto(25);
288 | 
289 | // all configuration.
290 | probar.setColor("#2980b9"); // change color of ProBar.
291 | probar.setWrapperColor("#ecf0f1"); // change background color of ProBar.
292 | probar.setSpeed(3000); // change Speed to 3 secondes.
293 | probar.goto(100); // reach 100%.
294 | probar.goto(100,2000); // reach 100% in 2 secondes
295 | probar.setFinishAnimation(false); // remove a finish animation.
296 | probar.setHeight(15); // set Height to 15px.
297 | probar.setRounded(15,15,15,15); // change Border radius of Probar. (topLeft, topRight, bottomLeft, bottomRight);
298 | probar.setRoundedInternal(15,15,15,15); // change Border radius of Probar Internel. (topLeft, topRight, bottomLeft, bottomRight);
299 | 						
300 | 					
301 |
302 |
303 | 304 | 305 |
306 |
307 |

308 | Fork me on Github 309 |

310 |
311 |
312 |
313 | 314 |
315 |
316 | 317 | 318 | 319 | 320 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 459 | 460 | 461 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ProBar 2 | 3 | ProBar is a progress bar with multiple options. 4 | 5 | # Features ! 6 | 7 | - config a ProBar color. 8 | - config a ProBar background. 9 | - config a Speed of ProBar. 10 | - config a "Goto" option with timing. 11 | - config a Finish animation. 12 | - cutomize with your own CSS. 13 | - config a Height of Probar. 14 | - config a Rounded Corners of Probar. 15 | - config a Rounded Corners of Probar in Internal. 16 | 17 | ### Requirement 18 | 19 | ProBar require [JQuery](https://code.jquery.com/). 20 | 21 | # How to Use : 22 | 23 | #### FIRST require CDN JQuery: 24 | 25 | ```html 26 | 30 | ``` 31 | 32 | #### Link `ProBar.js` from your html file 33 | ```html 34 | 35 | ``` 36 | 37 | #### Secondly instantiate ProBar: 38 | 39 | ```js 40 | var probar = new ProBar(options); 41 | ``` 42 | 43 | #### The options : 44 | 45 | ```js 46 | { 47 | color : "#2a2a2a", // color of the Progress bar. 48 | bgColor : "#efefef", // color background of the Progress bar 49 | speed : 0.3, // speed of animation. ( unit in secondes ) 50 | wrapper : "body", // the wrapper who append ProBar. if class ".class" ,if id "#id" 51 | finishAnimation : true || false, // config a finish animation. 52 | classNameBar : "setBar", // change a class to a custom class ( for Css ). 53 | wrapperId : "wrapperSetBar", // change a wrapper id for a custom Css. 54 | height:10, // give a height to Probar. 55 | rounded : { // use it to round Corners of Probar. 56 | topLeft : 25, 57 | topRight : 25, 58 | bottomLeft : 25, 59 | bottomRight : 25 60 | }, 61 | roundedInternal : { // use it to round Corners of Probar (internal). 62 | topLeft : 25, 63 | topRight : 25, 64 | bottomLeft : 25, 65 | bottomRight : 25 66 | } 67 | } 68 | ``` 69 | 70 | #### Functions : 71 | 72 | ```js 73 | probar.setColor("#2980b9"); // change color of ProBar. 74 | probar.setWrapperColor("#ecf0f1"); // change background color of ProBar. 75 | probar.setSpeed(3000); // change Speed to 3 secondes. 76 | probar.setFinishAnimation(false); // set animation to false. 77 | probar.goto(100); // reach 100%. 78 | probar.goto(100,2000); // reach 100% in 2 secondes. 79 | probar.setHeight(15); // set Height to 15px. 80 | probar.setRounded(15,15,15,15); // change Border radius of Probar. (topLeft, topRight, bottomLeft, bottomRight); 81 | probar.setRoundedInternal(15,15,15,15); // change Border radius of Probar (Internal). (topLeft, topRight, bottomLeft, bottomRight); 82 | ``` 83 | 84 | #### Upcoming features 85 | 86 | - Remove JQuery requirement. 87 | 88 | License 89 | ---- 90 | 91 | MIT 92 | 93 | # ** Made with love ❤ ** 94 | 95 | [jQuery]: 96 | --------------------------------------------------------------------------------