-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
83 lines (72 loc) · 1.5 KB
/
script.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$(document).ready(function() {
var map = {
0 : [],
1 : [1.1],
2 : [2],
3 : [3],
4 : [1.1,1.2,2],
5 : [2,3],
6 : [1.1,5],
7 : [2,5],
8 : [3,5],
9 : [1.1,3,5],
10 : [2,3,5],
11 : [1.1,2,3,5],
12 : [1.1,1.2,2,3,5]
}
var boxes = {
1.1 : ".one-top",
1.2 : ".one-bottom",
2 : ".two-half-left",
3 : ".three",
5 : ".five"
}
var colors = {
green: '#4CAF50',
blue: '#03A9F4',
white: '#FAFAFA',
red: '#FF4436'
}
function clearAllBoxes() {
for(i in boxes) {
$(boxes[i]).animate({
backgroundColor: colors.white
},{ duration: 1000, queue: false } );
}
}
function colorBoxes(hour, minutes) {
var _hour = map[hour];
var _minutes = map[minutes];
var _both = _.intersection(_hour,_minutes);
_hour.forEach(function(elem){
if(_both.indexOf(elem)<0){
$(boxes[elem]).animate({
backgroundColor: colors.red
},{ duration: 1000, queue: false } );
}
});
_minutes.forEach(function(elem){
if(_both.indexOf(elem)<0){
$(boxes[elem]).animate({
backgroundColor: colors.green
},{ duration: 1000, queue: false } );
}
});
_both.forEach(function(elem){
$(boxes[elem]).animate({
backgroundColor: colors.blue
},{ duration: 1000, queue: false } );
});
}
function updateTime() {
var date = new Date();
var hour = date.getHours()%12;
var minutes = Math.floor(date.getMinutes()/5);
console.log(hour);
console.log(minutes);
clearAllBoxes();
colorBoxes(hour,minutes);
}
updateTime();
setInterval(updateTime,300000);
});