-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
178 lines (152 loc) · 5.41 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var init = function() {
var pictureTitle = document.getElementById("picture-title");
var pictureDetails = document.getElementById("picture-details");
var pictureDescription = document.getElementById("picture-description");
setPictureDetails = function(index){
pictureTitle.innerHTML = pictureInformation.titles[index]
pictureDetails.innerHTML = pictureInformation.details[index]
pictureDescription.innerHTML = pictureInformation.descriptions[index]
}
var wallDescriptions = [
"Biography",
"Artworks",
"Artworks",
"Video"
]
var turnRightInfo = document.getElementById("turn-right-info");
var turnLeftInfo = document.getElementById("turn-left-info");
var escherImages = [
"images/escher/kaire_1.jpg",
"images/escher/kaire_2.jpg",
"images/escher/kaire_3.jpg",
"images/escher/pagrindinis_1.jpg",
"images/escher/pagrindinis_2.jpg",
"images/escher/pagrindinis_3.jpg",
"images/escher/desine_1.jpg",
"images/escher/desine_2.jpg",
"images/escher/desine_3.jpg"
];
var rotation = 0;
var lastSide = 3;
var box = document.querySelector('.container').children[0];
var controlButtons = document.querySelectorAll('.controls');
var transition = false;
var pictureTransition = false;
var selectedPicture = 0;
var sides = document.querySelectorAll('#cube .side');
var borders = document.querySelectorAll('#cube .border');
var pictures = document.querySelectorAll('#cube .picture');
var bigPicture = document.getElementById("big-picture")
var info = document.getElementById("info")
var closeInfoButton = document.getElementById("closeInfoButton")
var pictureText = document.getElementById("picture-text")
toggleVisibility = function(){
var side = ((rotation / 90) % 4 + 7) % 4;
turnLeftInfo.innerHTML = wallDescriptions[(side + 1) % 4]
turnRightInfo.innerHTML = wallDescriptions[(side + 3) % 4]
sides[side * 2].hidden = true;
sides[side * 2 + 1].hidden = true;
sides[lastSide * 2].hidden = false;
sides[lastSide * 2 + 1].hidden = false;
if (side < 3) {
borders[side * 2].hidden = true;
borders[side * 2 + 1].hidden = true;
};
if (lastSide < 3) {
borders[lastSide * 2].hidden = false;
borders[lastSide * 2 + 1].hidden = false;
};
lastSide = side;
}
buttonAnimation = function(name){
for (var i=0, len = controlButtons.length; i < len; i++) {
controlButtons[i].style.animationName = name;
}
}
buttonStyleToggle = function(name){
for (var i=0, len = controlButtons.length; i < len; i++) {
controlButtons[i].classList.toggle(name);
}
}
onButtonClick = function( event ){
if(transition) return;
if (this.id == "turn-left") {
rotation -= 90;
} else if (this.id == "turn-right") {
rotation += 90;
}
box.style.transform = "translateZ( 10vw ) rotateY( " + rotation + "deg ) translateY( 2vw )"
setTimeout(toggleVisibility, 1000);
transition = true;
buttonAnimation("button-fade");
};
for (var i=0, len = controlButtons.length; i < len; i++) {
controlButtons[i].addEventListener( 'click', onButtonClick, false);
}
var introScreen = document.getElementById("intro-screen");
var continueButton = document.getElementById("continue-button");
continueClick = function( event ){
introScreen.style.animationName = "fade";
}
continueButton.addEventListener('click', continueClick, false);
introScreen.addEventListener('animationend', function(){
this.hidden = true;
}, false);
box.addEventListener('transitionend', function(){
transition = false;
buttonAnimation("");
}, false);
function pictureFunction(index) {
var i = index;
function func() {
if(Math.floor(i / 3) != ((lastSide + 2) % 4)) return;
if (pictureTransition) return;
pictureTransition = true;
info.classList.toggle("appeared")
info.style.animationName = "info-appear"
// buttonAnimation("button-move-down")
// buttonStyleToggle("moved")
selectedPicture = i;
setPictureDetails(i);
bigPicture.src = escherImages[i]
bigPicture.style.animationName = "picture" + (selectedPicture % 3) + "-to-big"
bigPicture.style.animationDirection = "normal"
}
return func;
}
for (var i=0, len = pictures.length; i < len; i++) {
pictures[i].addEventListener( 'click', pictureFunction(i), false);
}
closeInfoButton.addEventListener('click', function(){
if (pictureTransition) return;
pictureTransition = true;
info.style.animationName = "info-fade"
bigPicture.style.animationName = "picture" + (selectedPicture % 3) + "-to-big"
bigPicture.style.animationDirection = "reverse"
// buttonAnimation("button-move-up")
// buttonStyleToggle("moved")
}, false);
info.addEventListener('animationend', function(e){
bigPicture.style.animationName = ""
pictureTransition = false;
if (e.animationName == "info-fade") {
info.classList.toggle("appeared")
};
}, false)
var musicButton = document.getElementById("musicToggle");
var musicOn = false;
var music = document.getElementById("music");
music.pause();
musicButton.classList.toggle("mute")
music.volume = 0.3;
musicButton.addEventListener('click', function(){
musicButton.classList.toggle("mute")
if (musicOn) {
music.pause()
} else {
music.play()
}
musicOn = !musicOn;
}, false);
};
window.addEventListener( 'DOMContentLoaded', init, false);