-
Notifications
You must be signed in to change notification settings - Fork 1
/
preMessage.js
62 lines (55 loc) · 1.96 KB
/
preMessage.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
window.onload = function () {
let messageDiv = document.createElement('div');
messageDiv.className = 'message';
document.body.appendChild(messageDiv);
let messages = [
'Dear Cori,',
'I love you dearly and walk with you through each of our journeys.',
'Please finish reading the following poem, then hold down "c" and move your mouse through the poem until no poem remains,'
];
function fadeOut(element, callback) {
let op = 1; // initial opacity
let timer = setInterval(function () {
if (op <= 0.1) {
clearInterval(timer);
element.style.display = 'none';
callback && callback();
}
element.style.opacity = op;
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op -= op * 0.1;
}, 50);
}
function fadeIn(element, callback) {
let op = 0.1; // initial opacity
element.style.display = 'block';
let timer = setInterval(function () {
if (op >= 1) {
clearInterval(timer);
callback && callback();
}
element.style.opacity = op;
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op += op * 0.1;
}, 50);
}
function showMessage(index) {
if (index >= messages.length) {
window.location.href = '/message.html';
return;
}
let message = document.createElement('p');
message.textContent = messages[index];
message.style.opacity = 0; // Start with invisible text
messageDiv.appendChild(message);
fadeIn(message, function() {
setTimeout(function () {
fadeOut(message, function() {
message.remove();
showMessage(index + 1);
});
}, 3000); // Time the message stays visible
});
}
showMessage(0);
}