-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathturbine_tab_animation.js
executable file
·69 lines (61 loc) · 2.29 KB
/
turbine_tab_animation.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
function changeTurbineState(e){
const target = Array.from(turbiner).indexOf(e.target);
const target_src = turbiner[target].src;
if (target_src.indexOf("turbin_av") > -1){
changeTurbineUsage(target, 1);
} else {
changeTurbineUsage(target, 0);
}
}
const turbiner = document.querySelectorAll("#turbinpannel > div > img");
for (let i = 0; i < turbiner.length; i++){
turbiner[i].addEventListener("click", changeTurbineState);
}
let rotation = 0;
let turbineState = new Array(20).fill({'capacityUsage': 0}); // so i dont get undefined, when not having the values
setInterval(() => {
turbines().then(value => {
turbineState = value.slice();
for (let i = 0; i < turbiner.length; i++){
if (turbineState[i].capacityUsage){
turbiner[i].src = "media/turbin_på.png";
} else {
turbiner[i].src = "media/turbin_av.png";
}
}
});
}, 1000);
setInterval(() => {
for (let i = 0; i < turbiner.length; i++){
if (turbineState[i].capacityUsage){
turbiner[i].style.transform = "rotate(" + rotation + "deg)";
}
}
rotation+= 4;
}, 30);
// under denne kommentaren er in og ut av skjermen animasjon over er panelet
let turbinPanelOpen = false;
const turbin_tab_BUTTON = document.getElementById("turbin_tab");
turbin_tab_BUTTON.addEventListener("click", inOutTurbineTab);
const turbin_tab_DIV = document.getElementById("turbinpannel");
const filterDiv = document.getElementById("filter_blur");
let inoutcounter_turbinpanel = 1;
function inOutTurbineTab() {
inoutcounter_turbinpanel++;
if (inoutcounter_turbinpanel % 2 == 0){
if (sidebarOpen == true){
inOutSidebar();
}
turbinPanelOpen = true;
filterDiv.style.filter = "blur(35px)"
turbin_tab_DIV.style.left = "calc((100% - 1185px) / 2 + 50px / 2";
turbin_tab_BUTTON.style.left = "calc(((100% - 1185px) / 2 + 50px / 2) - 30px)";
turbin_tab_BUTTON.childNodes[0].src = "media/arrow_right.png";
} else {
turbinPanelOpen = false;
filterDiv.style.filter = "blur(0px)"
turbin_tab_DIV.style.left = "100%";
turbin_tab_BUTTON.style.left = "calc(100% - 30px)";
turbin_tab_BUTTON.childNodes[0].src= "media/arrow_left.png";
}
}