-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (42 loc) · 1.25 KB
/
app.js
File metadata and controls
49 lines (42 loc) · 1.25 KB
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
var bg1 = $('#background-stats-1');
var bg2 = $('#background-stats-2');
var valueA = $('#a');
var valueB = $('#b');
var total = $('#result');
function animateStats (a,b){
if(a + b > 0){
var percentA = a/(a+b)*100;
var percentB = 100-percentA;
bg1.width((percentA-0.3)+"%");
bg2.width(percentB+"%");
}
}
function updateScores (){
$.get("https://kmti6g8um6.execute-api.eu-central-1.amazonaws.com/my-vote", null, function(result,status){
if ("success" == status) {
console.log(result);
data = JSON.parse(result);
var a = parseInt(data.a || 0);
var b = parseInt(data.b || 0);
animateStats(a, b);
if(a + b > 0){
valueA.text(Math.round((a/(a+b) * 100) * 10) / 10 + "%");
valueB.text(Math.round((b/(a+b) * 100) * 10) / 10 + "%");
total.text("Всего голосов: " + (a + b))
}
} else {
console.log(result);
}
});
}
$.ajaxSetup({
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
document.body.style.opacity=1;
updateScores();
setInterval(function() {
updateScores();
}, 3000);