-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (50 loc) · 1.77 KB
/
index.js
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
$(document).ready(function(){
var $pc = $('#progressController');
var $pCaption = $('.progress-bar p');
var iProgress = document.getElementById('inactiveProgress');
var aProgress = document.getElementById('activeProgress');
var iProgressCTX = iProgress.getContext('2d');
drawInactive(iProgressCTX);
$pc.on('change', function(){
var percentage = $(this).val() / 100;
console.log(percentage + '%');
drawProgress(aProgress, percentage, $pCaption);
});
function drawInactive(iProgressCTX){
iProgressCTX.lineCap = 'square';
//outer ring
iProgressCTX.beginPath();
iProgressCTX.lineWidth = 15;
iProgressCTX.strokeStyle = '#e1e1e1';
iProgressCTX.arc(137.5,137.5,129,0,2*Math.PI);
iProgressCTX.stroke();
//progress bar
iProgressCTX.beginPath();
iProgressCTX.lineWidth = 0;
iProgressCTX.fillStyle = '#e6e6e6';
iProgressCTX.arc(137.5,137.5,121,0,2*Math.PI);
iProgressCTX.fill();
//progressbar caption
iProgressCTX.beginPath();
iProgressCTX.lineWidth = 0;
iProgressCTX.fillStyle = '#fff';
iProgressCTX.arc(137.5,137.5,100,0,2*Math.PI);
iProgressCTX.fill();
}
function drawProgress(bar, percentage, $pCaption){
var barCTX = bar.getContext("2d");
var quarterTurn = Math.PI / 2;
var endingAngle = ((2*percentage) * Math.PI) - quarterTurn;
var startingAngle = 0 - quarterTurn;
bar.width = bar.width;
barCTX.lineCap = 'square';
barCTX.beginPath();
barCTX.lineWidth = 20;
barCTX.strokeStyle = '#76e1e5';
barCTX.arc(137.5,137.5,111,startingAngle, endingAngle);
barCTX.stroke();
$pCaption.text( (parseInt(percentage * 100, 10)) + '%');
}
var percentage = $pc.val() / 100;
drawProgress(aProgress, percentage, $pCaption);
});