-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
292 lines (240 loc) · 12.1 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
$(document).ready(function() {
$('.backyong-before').hover(function() {
$('#backyong-speech-bubble').toggleClass('active')
$('#backyong-heart').toggleClass('active');
});
$('.bbugong-before').hover(function() {
$('#bbugong-speech-bubble').toggleClass('active');
$('#bbugong-heart').toggleClass('active');
});
});
// 리셋 버튼 클릭
function clickReset() {
document.getElementById('reset-button').addEventListener('click', function() {
// 초기 상태로 되돌리기
var mainImage = document.querySelector('.center_elements img#main-image');
mainImage.style.display = 'block';
document.querySelector('.center_elements p').style.display = 'block';
document.querySelector('.center_elements img#angle-down').style.display = 'block';
document.querySelector('.backyong').style.display = 'none';
document.querySelector('.bbugong').style.display = 'none';
document.querySelector('.buildings').style.display = 'none';
document.querySelector('#toggleBtn').style.display = 'none';
document.querySelector('#sidebar').style.display = 'none';
var backyong_before = document.querySelector('.backyong-before');
var bbugong_before = document.querySelector('.bbugong-before');
var overlay = document.getElementById('modal-overlay');
// 백경이와 뿌공이 모두 보이게 하기
backyong_before.style.display = 'block';
bbugong_before.style.display = 'block';
overlay.style.display = 'none';
mainImage.style.position = 'absolute'; // ensure it is positioned absolutely
mainImage.style.left = '180px'; // desired left position
mainImage.style.top = '-280px'; // desired top position
const toggleBtn = document.getElementById('toggleBtn');
const sidebar = document.getElementById('sidebar');
toggleBtn.addEventListener('click', () => {
sidebar.classList.toggle('open');
toggleBtn.innerHTML = sidebar.classList.contains('open') ? '<' : '>';
toggleBtn.style.left = sidebar.classList.contains('open') ? '250px' : '0px';
toggleBtn.style.top = sidebar.classList.contains('open') ? '400px' : '400px';
});
});
}
const audioContainer = document.querySelector('#audioContainer');
const audioToggleButton = document.querySelector('#audio-toggleButton');
audioContainer.autoplay = false; // 웹을 열면 자동 재생x
audioContainer.loop = true; // 반복 재생 설정
// 버튼 클릭 시 재생 및 일시 정지 토글
function toggleMusic() {
if (audioContainer.paused) {
audioContainer.play();
audioToggleButton.textContent = '🔊'; // 볼륨 모양 버튼
} else {
audioContainer.pause();
audioToggleButton.textContent = '🔇'; // 금지 모양 버튼
}
}
function rotateAndMove() {
// 회전 애니메이션 추가
document.querySelector('.background-grid').classList.add('rotate-left');
document.querySelector('.center_elements img#main-image').classList.add('rotate-left');
document.querySelector('.center_elements p').classList.add('rotate-left');
document.querySelector('.center_elements img#angle-down').classList.add('rotate-left');
document.querySelector('.floating_mini_icons').style.display = 'none';
document.querySelector('.center_elements button').style.display = 'none';
document.querySelector('.center_elements p').style.display = 'block';
document.querySelector('.center_elements img#angle-down').style.display = 'block';
// 백경이, 뿌공이 이미지 이동
const backyong_before = document.getElementById('backyong-before');
const bbugong_before = document.getElementById('bbugong-before');
backyong_before.style.left = '-20%';
bbugong_before.style.left = '-20%';
// 이동 애니메이션 후, 중앙 이미지 왼쪽에 정렬
setTimeout(() => {
backyong_before.style.left = 'calc(50% - 100px)';
bbugong_before.style.left = 'calc(50% - 100px)'; // 중앙 이미지 왼쪽에 위치
}, 100); // 약간의 지연을 줘서 자연스럽게 이동 시작
}
// 팝업 토글 함수
function togglePopup(character) {
var backyong_popup = document.getElementById('backyong-popup');
var bbugong_popup = document.getElementById('bbugong-popup');
var overlay = document.getElementById('modal-overlay');
backyong_popup.style.display = 'none';
bbugong_popup.style.display = 'none';
overlay.style.display = 'none';
if (character == 'backyong-before')
backyong_popup.style.display = 'block';
else if (character == 'bbugong-before')
bbugong_popup.style.display = 'block';
}
document.getElementById('backyong-before').addEventListener('click', function() {
togglePopup('backyong-before');
});
document.getElementById('bbugong-before').addEventListener('click', function() {
togglePopup('bbugong-before');
});
document.getElementById('modal-overlay').addEventListener('click', function() {
var backyong_popup = document.getElementById('backyong-popup');
var bbugong_popup = document.getElementById('bbugong-popup');
var overlay = document.getElementById('modal-overlay');
backyong_popup.style.display = 'none';
bbugong_popup.style.display = 'none';
overlay.style.display = 'none';
});
// 팝업 닫기 함수
function closeBackyongPopup() {
var backyong_popup = document.getElementById('backyong-popup');
var overlay = document.getElementById('modal-overlay');
backyong_popup.style.display = 'none';
overlay.style.display = 'none';
}
function closeBbugongPopup() {
var bbugong_popup = document.getElementById('bbugong-popup');
var overlay = document.getElementById('modal-overlay');
bbugong_popup.style.display = 'none';
overlay.style.display = 'none';
}
// 백경이 선택 함수
function toggleBackyong() {
var backyong_popup = document.getElementById('backyong-popup');
var overlay = document.getElementById('modal-overlay');
document.querySelector('.backyong-before').style.display = 'none';
document.querySelector('.bbugong-before').style.display = 'none';
document.querySelector('.backyong').style.display = 'block';
document.querySelector('.center_elements img#main-image').style.display = 'none';
document.querySelector('.center_elements p').style.display = 'none';
document.querySelector('.center_elements img#angle-down').style.display = 'none';
document.querySelector('.buildings').style.display = 'block';
document.querySelector('#toggleBtn').style.display = 'block';
document.querySelector('#sidebar').style.display = 'block';
backyong_popup.style.display = 'none';
overlay.style.display = 'none';
document.querySelector('#reset-button').style.display = 'block';
var backyong = document.querySelector('.backyong');
backyong.classList.add('animate-right'); //백경이 중앙으로 이동
document.querySelector('.bbugong').style.display = 'none';// 뿌공이 사라지기
// 백경이 마우스 포인터에 따라 이동시키기
// 백경이 애니메이션 함수
function animateBackyong(startX, startY, endX, endY) {
let progress = 0;
const duration = 500; // 애니메이션 지속 시간 (밀리초)
const startTime = performance.now();
function step(currentTime) {
progress = (currentTime - startTime) / duration;
if (progress < 1) {
const x = startX + (endX - startX) * progress;
const y = startY + (endY - startY) * progress;
backyong.style.left = `${x}px`;
backyong.style.top = `${y}px`;
console.log(x, y);
requestAnimationFrame(step);
} else {
backyong.style.left = `${endX}px`;
backyong.style.top = `${endY}px`;
}
}
requestAnimationFrame(step);
}
document.addEventListener('click', (event) => {
const backyong = document.querySelector('.backyong');
if (!backyong) return;
backyong.classList.remove('animate-right'); // 백경이 중앙 이동 에니메이션 제거
const startX = parseInt(backyong.style.left) || 0;
const startY = parseInt(backyong.style.top) || 0;
const endX = event.clientX - backyong.offsetWidth / 2;
const endY = event.clientY - backyong.offsetHeight / 2;
animateBackyong(startX, startY, endX, endY);
console.log(startX, startY, endX, endY);
});
const toggleBtn = document.getElementById('toggleBtn');
const sidebar = document.getElementById('sidebar');
toggleBtn.addEventListener('click', () => {
sidebar.classList.toggle('open');
toggleBtn.innerHTML = sidebar.classList.contains('open') ? '<' : '>';
toggleBtn.style.left = sidebar.classList.contains('open') ? '250px' : '0px';
toggleBtn.style.top = sidebar.classList.contains('open') ? '400px' : '400px';
});
}
// 뿌공이 선택 함수
function toggleBbugong() {
var bbugong_popup = document.getElementById('bbugong-popup');
var overlay = document.getElementById('modal-overlay');
document.querySelector('.backyong-before').style.display = 'none';
document.querySelector('.bbugong-before').style.display = 'none';
document.querySelector('.bbugong').style.display = 'block';
document.querySelector('.center_elements img#main-image').style.display = 'none';
document.querySelector('.center_elements p').style.display = 'none';
document.querySelector('.center_elements img#angle-down').style.display = 'none';
document.querySelector('.buildings').style.display = 'block';
document.querySelector('#toggleBtn').style.display = 'block';
document.querySelector('#sidebar').style.display = 'block';
bbugong_popup.style.display = 'none';
overlay.style.display = 'none';
document.querySelector('#reset-button').style.display = 'block';
var bbugongElement = document.querySelector('.bbugong');
bbugongElement.classList.add('animate-left'); // 뿌공이 중앙으로 이동
document.querySelector('.backyong').style.display = 'none'; // 백경이 사라지기
// 뿌공이 마우스 포인터에 따라 이동시키기
// 뿌공이 애니메이션 함수
function animateBbugong(startX, startY, endX, endY) {
let progress = 0;
const duration = 500; // 애니메이션 지속 시간 (밀리초)
const startTime = performance.now();
function step(currentTime) {
progress = (currentTime - startTime) / duration;
if (progress < 1) {
const x = startX + (endX - startX) * progress;
const y = startY + (endY - startY) * progress;
bbugong.style.left = `${x}px`;
bbugong.style.top = `${y}px`;
console.log(x, y);
requestAnimationFrame(step);
} else {
bbugong.style.left = `${endX}px`;
bbugong.style.top = `${endY}px`;
}
}
requestAnimationFrame(step);
}
document.addEventListener('click', (event) => {
const bbugong = document.querySelector('.bbugong');
if (!bbugong) return;
bbugong.classList.remove('animate-left'); // 뿌공이 중앙 이동 에니메이션 제거
const startX = parseInt(bbugong.style.left) || 0;
const startY = parseInt(bbugong.style.top) || 0;
const endX = event.clientX - bbugong.offsetWidth / 2;
const endY = event.clientY - bbugong.offsetHeight / 2;
animateBbugong(startX, startY, endX, endY);
console.log(startX, startY, endX, endY);
});
const toggleBtn = document.getElementById('toggleBtn');
const sidebar = document.getElementById('sidebar');
toggleBtn.addEventListener('click', () => {
sidebar.classList.toggle('open');
toggleBtn.innerHTML = sidebar.classList.contains('open') ? '<' : '>';
toggleBtn.style.left = sidebar.classList.contains('open') ? '250px' : '0px';
toggleBtn.style.top = sidebar.classList.contains('open') ? '400px' : '400px';
});
}