-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
202 lines (153 loc) · 6.58 KB
/
Copy pathscript.js
File metadata and controls
202 lines (153 loc) · 6.58 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
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
function changeImage(img) {
var fridge = document.getElementById("fridge");
fridge.src = img + '';
}
var intro = ['รู้ไหมว่าขยะพวกนี้มาจากไหน', 'ของเหลือในตู้เย็นของคุณ',
'เป็นส่วนหนึ่งที่ทำให้เกิดขยะเหล่านี้'];
introIndex = 1;
function changeText() {
let txt = document.querySelector(".txt");
txt.textContent = intro[introIndex];
introIndex++;
}
var pg2_txt = ['รู้ไหมว่าขยะพวกนี้มาจากไหน ?', 'ของเหลือในตู้เย็นของคุณ', 'เป็นส่วนหนึ่งที่ทำให้เกิดขยะเหล่านี้'];
pg2_txt_Index = 1;
function changeText1() {
var pg2_textElement = document.getElementById('page2_Text');
pg2_textElement.style.opacity = '0';
setTimeout(function() {
pg2_textElement.innerHTML = pg2_txt[pg2_txt_Index] + '<p style="font-size: 0.3em;">กดเพื่อไปต่อ</p>';
pg2_textElement.style.opacity = '1';
if (pg2_txt_Index <= pg2_txt.length - 1) {
pg2_txt_Index++;
}
else {
// arrow copy anad paste: ⬆ ⬇ ⬅ ➡
pg2_textElement.innerHTML = '⬇ ⬇'
pg2_textElement.onclick = null;
// pg2_txt_Index = 0;
}
}, 500);
}
var pg5_txt = ['"เหลือดีกว่าขาด ?"', 'นิสัยการชอบซื้อไปเผื่อตุนเอาไว้ก่อน ?', 'เป็นคุณรึเปล่า ?'];
pg5_txt_Index = 1;
function changeText2() {
var pg5_textElement = document.getElementById('page5_Text');
pg5_textElement.style.opacity = '0';
setTimeout(function() {
pg5_textElement.innerHTML = pg5_txt[pg5_txt_Index] + '<p style="font-size: 0.3em;">กดเพื่อไปต่อ</p>';
pg5_textElement.style.opacity = '1';
if (pg5_txt_Index <= pg5_txt.length - 1) {
pg5_txt_Index++
}
else {
document.getElementById('page5_Text').style.cursor = 'default';
pg5_textElement.innerHTML = '<div style="font-size: 3rem; text-align: center; padding: 5%">ลองมาพิสูจน์กัน</div>'+
'<div style="font-size: 1rem;text-align: center;">กดเข้าร้านค้าเพื่อไปต่อ</div>'+
'<audio id="digitonza55" src="Sound Effect/3 Store Scene/Store-Door.mp3"></audio>'+
'<a id="pong" onclick="doorbell()" style="display: flex;cursor: pointer;align-items: center;justify-content: center;padding: 1%"> <img src="img file/page_5/Supermarket.png" onclick="pongaum()"'+
'style="width:70%; margin:auto; align-items: center;"> </a>';
pg5_textElement.onclick = null;
initiateSmoothScroll();
}
}, 500);
}
function doorbell() {
setTimeout(function() {
window.location.href = 'supermarket.html';
}, 4000);
}
function pongaum() {
const Store = document.getElementById('pong')
const audio = document.getElementById('digitonza55');
Store.addEventListener('click', () => {
audio.play();})
}
function initiateSmoothScroll() {
setTimeout(function () {
window.scrollTo({
top: document.body.scrollHeight,
behavior: 'smooth'
});
}, 1000);
}
function up() {
const bin = document.getElementById("Binbag");
// const audio = document.getElementById("trash-bag-audio");
// // Play the audio when the function is called
// audio.play();
const audio = document.getElementById("trash-bag-audio");
if (audio) {
audio.play();
audio.onended = function() {
audio.remove(); // ลบเสียงเมื่อเล่นเสร็จ
}
}
bin.style.transform = 'translateY(-70%)';
}
// how 2 disable scroll vvvvvvvvvvvvvvvvvv
// https://www.geeksforgeeks.org/how-to-disable-scrolling-temporarily-using-javascript/
// ล็อกหน้าจอ ถุงขยะ
document.addEventListener('DOMContentLoaded', () => {
let isScrollLocked = true;
// ล็อกการเลื่อนหน้าจอที่ระดับนึง
const lockPosition = window.innerHeight * 5.5;
window.addEventListener('scroll', () => {
if (isScrollLocked && window.scrollY >= lockPosition) {
window.scrollTo(0, lockPosition);
}
});
// ปลดล็อกเมื่อคลิกที่ปุ่ม
const unlock_bin = document.getElementById('unlock_bin');
unlock_bin.addEventListener('click', () => {
isScrollLocked = false;
});
});
// ล็อกหน้าจอ ตู้เย็น
document.addEventListener('DOMContentLoaded', () => {
let isScrollLocked = true;
// ล็อกการเลื่อนหน้าจอที่ระดับนึง
const lockPosition = window.innerHeight * 1.1;
window.addEventListener('scroll', () => {
if (isScrollLocked && window.scrollY >= lockPosition) {
window.scrollTo(0, lockPosition);
}
});
// ปลดล็อกเมื่อคลิกที่ปุ่ม
// const unlock_frige = document.getElementById('unlock_fridge');
const unlock_frige = document.querySelector('.bounce');
unlock_frige.addEventListener('click', () => {
isScrollLocked = false;
});
});
// ฝาตู้เย็นหาย
function bounceAndDisappear() {
const hitbox = document.querySelector('.bounce');
const audio = document.getElementById('fridge-open-audio');
// Add a click event listener to the image
hitbox.addEventListener('click', () => {
image = document.querySelector('#unlock_fridge');
image.style.transform = 'scale(1.2)';
audio.play(); // Play the audio when the click event occurs
setTimeout(() => {
image.style.opacity = '0';
image.style.transform = 'scale(0.8)';
document.querySelector('#hotpoint1').style.opacity = "0%";
setTimeout(() => {
image.style.display = 'none';
document.querySelector('#hotpoint1').style.display = 'none';
}, 1000); // 1000 milliseconds (1 second)
}, 200); // 200 milliseconds
});
}
// const animatedImage = document.getElementById('animatedImage');
// window.addEventListener('scroll', () => {
// const scrollY = window.scrollY;
// const windowHeight = window.innerHeight;
// // กำหนดความคมชัดของรูปภาพเมื่อเลื่อน scrollY ถึงค่าที่กำหนด
// if (scrollY >= 1000) {
// animatedImage.style.opacity = '1';
// } else {
// animatedImage.style.opacity = '0';
// }
// });