Progress Meter Using CSS and Javascript

Submitted by: 
Language: 
Visitors have accessed this post 1384 times.

In this tutorial, I am going to teach you on to make a beautiful progress meter using CSS and Javascript. Just download the source code below and follow the instructions.

Instructions

Creating our index.php page

In this page we will be creating our html code. don't forget to place the css link on the head tag of the page and place the javascript link below the body tag.

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Progress Meter</title>
  5. <link rel="stylesheet" type="text/css" href="style.css">
  6. </head>
  7. <body>
  8. <form>
  9. <div class="prog"></div>
  10. <input type="checkbox" name="progress-tasks" id="progress-task1" value="Task 1" checked required>
  11. <label for="progress-task1" class="progress-task">Task 1</label>
  12. <input type="checkbox" name="progress-tasks" id="progress-task2" value="Task 2" checked required>
  13. <label for="progress-task2" class="progress-task">Task 2</label>
  14. <input type="checkbox" name="progress-tasks" id="progress-task3" value="Task 3" required>
  15. <label for="progress-task3" class="progress-task">Task 3</label>
  16. <input type="checkbox" name="progress-tasks" id="progress-task4" value="Task 4" required>
  17. <label for="progress-task4" class="progress-task">Task 4</label>
  18. <input type="checkbox" name="progress-tasks" id="progress-task5" value="Task 5" required>
  19. <label for="progress-task5" class="progress-task">Task 5</label>
  20. <input type="checkbox" name="progress-tasks" id="progress-task6" value="Task 6" required>
  21. <label for="progress-task6" class="progress-task">Task 6</label>
  22. <label for="progress-tasks-percentage" class="progress-tasks-completed"><span>0</span><sup>%</sup> Completed</label>
  23. <progress id="progress-tasks-percentage" name="progress-tasks-percentage" min="0" max="100"></progress>
  24. </form>
  25. </body>
  26. <script type="text/javascript" src="script.js"></script>
  27.  
  28. </html>

Creating our style.css page

In this page, we will be creating our css style for our simple program and name it as style.css

  1. @import "compass/css3";
  2.  
  3. @import url(<a href="http://weloveiconfonts.com/api/?family=entypo" rel="nofollow">http://weloveiconfonts.com/api/?family=entypo</a>);
  4.  
  5. body {
  6. background: #888;
  7. color: #fff;
  8. }
  9.  
  10. form {
  11. position: relative;
  12. border: 5px solid #59616C;
  13. border-radius: 400px;
  14. width: 400px;
  15. height: 400px;
  16. margin: 24px auto;
  17. }
  18.  
  19. input[type=checkbox] {
  20. position: absolute;
  21. overflow: hidden;
  22. clip: rect(0 0 0 0);
  23. height: 1px;
  24. width: 1px;
  25. margin: -1px;
  26. padding: 0;
  27. border: 0;
  28. }
  29.  
  30. label.progress-task {
  31. position: absolute;
  32. left: 0;
  33. width: 400px;
  34. cursor: pointer;
  35. font: 32px/345px sans-serif;
  36. text-align: center;
  37. color: transparent;
  38. }
  39.  
  40. label.progress-task:before,
  41. label.progress-task:after {
  42. position: absolute;
  43. display: block;
  44. width: 24px;
  45. height: 24px;
  46. content: ' ';
  47. border-radius: 24px;
  48. cursor: pointer;
  49. }
  50.  
  51. label.progress-task:before {
  52. border: 5px solid #59616c;
  53. z-index: 1;
  54. }
  55.  
  56. label.progress-task:after {
  57. background: #2c3642;
  58. border: 12px solid #2c3642;
  59. position: absolute;
  60. }
  61.  
  62. input[type=checkbox]:invalid ~ label.progress-task {
  63. color: #fff;
  64. }
  65.  
  66. input[type=checkbox]:invalid ~ label.progress-task:before {
  67. border-color: #fdce7e;
  68. }
  69.  
  70. input[type=checkbox]:invalid ~ label.progress-task:after {
  71. content: '...';
  72. color: #fdce7e;
  73. font: bold 14px/15px 'entypo', sans-serif;
  74. text-align: center;
  75. }
  76.  
  77. input[type=checkbox]:invalid + label + input[type=checkbox]:invalid + label,
  78. input[type=checkbox]:invalid + label + input[type=checkbox]:invalid + label:after {
  79. color: transparent;
  80. }
  81.  
  82. input[type=checkbox]:invalid + label + input[type=checkbox]:invalid + label:before {
  83. border-color: #59616c;
  84. }
  85.  
  86. input[type=checkbox]:checked + label:before {
  87. content: '\2713';
  88. color: #00D9d1;
  89. font: bold 14px/24px 'entypo', sans-serif;
  90. border-color: #00D9d1;
  91. text-align: center;
  92. background: #2c3642;
  93. }
  94.  
  95. input[type=checkbox]:checked + label:after {
  96. display: none;
  97. }
  98.  
  99. #progress-task1 + label:before {
  100. left: 190px;
  101. top: -20px;
  102. }
  103.  
  104. #progress-task1 + label:after {
  105. left: 183px;
  106. top: -27px;
  107. }
  108.  
  109. #progress-task2 + label:before {
  110. left: 354px;
  111. top: 75px;
  112. }
  113.  
  114. #progress-task2 + label:after {
  115. left: 347px;
  116. top: 69px;
  117. }
  118.  
  119. #progress-task3 + label:before {
  120. left: 354px;
  121. top: 290px;
  122. }
  123.  
  124. #progress-task3 + label:after {
  125. left: 347px;
  126. top: 284px;
  127. }
  128.  
  129. #progress-task4 + label:before {
  130. left: 190px;
  131. top: 385px;
  132. }
  133.  
  134. #progress-task4 + label:after {
  135. left: 183px;
  136. top: 378px;
  137. }
  138.  
  139. #progress-task5 + label:before {
  140. left: 14px;
  141. top: 290px;
  142. }
  143.  
  144. #progress-task5 + label:after {
  145. left: 7px;
  146. top: 284px;
  147. }
  148.  
  149. #progress-task6 + label:before {
  150. left: 14px;
  151. top: 75px;
  152. }
  153.  
  154. #progress-task6 + label:after {
  155. left: 7px;
  156. top: 69px;
  157. }
  158.  
  159. progress {
  160. position: absolute;
  161. top: 320px;
  162. left: 175px;
  163. width: 64px;
  164. height: 5px;
  165. appearance: none;
  166. -moz-appearance: none;
  167. -webkit-appearance: none;
  168. border: none;
  169. background-size: auto;
  170. color: #00D9d1;
  171. background: #59616c !important;
  172. }
  173.  
  174. progress::-moz-progress-bar {
  175. background: #00D9d1;
  176. }
  177.  
  178. progress::-webkit-progress-value {
  179. background: #00D9d1;
  180. }
  181.  
  182. progress::-webkit-progress-bar {
  183. background: #59616c;
  184. }
  185.  
  186. label.progress-tasks-completed {
  187. position: absolute;
  188. left: 0;
  189. width: 400px;
  190. font: 20px/455px sans-serif;
  191. text-align: center;
  192. color: #fdce7e;
  193. }
  194.  
  195. label.progress-tasks-completed:before {
  196. position: absolute;
  197. top: 320px;
  198. left: 175px;
  199. background: -moz-linear-gradient(left, transparent 0, transparent 7px, #2c3642 8px, #2c3642 11px, transparent 11px, transparent 18px, #2c3642 19px, #2c3642 22px, transparent 22px, transparent 29px, #2c3642 30px, #2c3642 33px, transparent 33px, transparent 40px, #2c3642 41px, #2c3642 44px, transparent 44px, transparent 51px, #2c3642 52px, #2c3642 55px, transparent 55px, transparent 62px, #2c3642 63px, #2c3642 66px);
  200. background: -webkit-linear-gradient(left, transparent 0, transparent 7px, #2c3642 8px, #2c3642 11px, transparent 11px, transparent 18px, #2c3642 19px, #2c3642 22px, transparent 22px, transparent 29px, #2c3642 30px, #2c3642 33px, transparent 33px, transparent 40px, #2c3642 41px, #2c3642 44px, transparent 44px, transparent 51px, #2c3642 52px, #2c3642 55px, transparent 55px, transparent 62px, #2c3642 63px, #2c3642 66px);
  201. background: -o-linear-gradient(left, transparent 0, transparent 7px, #2c3642 8px, #2c3642 11px, transparent 11px, transparent 18px, #2c3642 19px, #2c3642 22px, transparent 22px, transparent 29px, #2c3642 30px, #2c3642 33px, transparent 33px, transparent 40px, #2c3642 41px, #2c3642 44px, transparent 44px, transparent 51px, #2c3642 52px, #2c3642 55px, transparent 55px, transparent 62px, #2c3642 63px, #2c3642 66px);
  202. background: -ms-linear-gradient(left, transparent 0, transparent 7px, #2c3642 8px, #2c3642 11px, transparent 11px, transparent 18px, #2c3642 19px, #2c3642 22px, transparent 22px, transparent 29px, #2c3642 30px, #2c3642 33px, transparent 33px, transparent 40px, #2c3642 41px, #2c3642 44px, transparent 44px, transparent 51px, #2c3642 52px, #2c3642 55px, transparent 55px, transparent 62px, #2c3642 63px, #2c3642 66px);
  203. background: linear-gradient(to right, transparent 0, transparent 7px, #2c3642 8px, #2c3642 11px, transparent 11px, transparent 18px, #2c3642 19px, #2c3642 22px, transparent 22px, transparent 29px, #2c3642 30px, #2c3642 33px, transparent 33px, transparent 40px, #2c3642 41px, #2c3642 44px, transparent 44px, transparent 51px, #2c3642 52px, #2c3642 55px, transparent 55px, transparent 62px, #2c3642 63px, #2c3642 66px);
  204. width: 64px;
  205. height: 5px;
  206. content: ' ';
  207. display: block;
  208. z-index: 1;
  209. }
  210.  
  211. label.progress-tasks-completed sup {
  212. font-size: 12px;
  213. }
  214.  
  215. .prog {
  216. position: relative;
  217. float: left;
  218. width: 400px;
  219. height: 400px;
  220. margin: -5px 0 0 -5px;
  221. }
  222.  
  223. .prog > #slice {
  224. position: absolute;
  225. width: 410px;
  226. height: 410px;
  227. clip: rect(0,410px,410px,205px);
  228. }
  229.  
  230. .prog > #slice.gt50 {
  231. clip: rect(auto, auto, auto, auto);
  232. }
  233.  
  234. .prog > #slice > .pie {
  235. border: 5px solid #00D9d1;
  236. position: absolute;
  237. width: 400px;
  238. height: 400px;
  239. clip: rect(0,205px,410px,0);
  240. -moz-border-radius: 400px;
  241. -webkit-border-radius: 400px;
  242. border-radius: 400px;
  243. }
  244.  
  245. .prog > #slice > .pie.fill {
  246. -moz-transform: rotate(180deg) !important;
  247. -webkit-transform: rotate(180deg) !important;
  248. -o-transform: rotate(180deg) !important;
  249. transform: rotate(180deg) !important;
  250. }

Lastly, Creating our script.js

In this page, we will be creating our javascript code. Name it as script.js

  1. // JS updates <progress> element and .prog pie radius
  2. var checkbox = document.getElementsByName('progress-tasks'),
  3. checkboxLen = checkbox.length,
  4. checkboxChecked = [],
  5. i,
  6. meter = document.getElementsByName('progress-tasks-percentage')[0],
  7. meterLabel = document.querySelector('.progress-tasks-completed'),
  8. meterCurrVal,
  9. progRadius = document.querySelector('.prog'),
  10. progRadiusPie,
  11. deg;
  12.  
  13. function updateProgressVal () {
  14. meterCurrVal = Math.floor((checkboxChecked.length / checkboxLen) * 100);
  15. meter.setAttribute('value', meterCurrVal);
  16. meterLabel.getElementsByTagName('span')[0].innerHTML = meterCurrVal;
  17.  
  18. progRadius.innerHTML = '<div class="percent"></div><div id="slice"' + (meterCurrVal > 50 ? ' class="gt50"' : '') + '><div class="pie"></div>' + (meterCurrVal > 50 ? '<div class="pie fill"></div>' : '') + '</div>';
  19.  
  20. deg = (360 / 100) * meterCurrVal;
  21. progRadiusPie = document.querySelector('#slice .pie');
  22. progRadiusPie.style.mozTransform = 'rotate(' + deg + 'deg)';
  23. progRadiusPie.style.webkitTransform = 'rotate(' + deg + 'deg)';
  24. progRadiusPie.style.oTransform = 'rotate(' + deg + 'deg)';
  25. progRadiusPie.style.msTransform = 'rotate(' + deg + 'deg)';
  26. progRadiusPie.style.transform = 'rotate(' + deg + 'deg)';
  27. }
  28.  
  29. for (i = 0; i < checkboxLen; i++) {
  30. if (checkbox[i].checked) {
  31. checkboxChecked.push(checkbox[i]);
  32. }
  33.  
  34. checkbox[i].onchange = function () {
  35. (this.checked) ? checkboxChecked.push(this) : checkboxChecked.splice(checkboxChecked.indexOf(this), 1);
  36. updateProgressVal();
  37. }
  38. }
  39.  
  40. updateProgressVal();

Finally, you've just created a Progress Meter than you can use for your projects or system. For more questions and inquiries, feel free to comment below or email me at [email protected]


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.