-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
137 lines (117 loc) · 3.43 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
// Real quick add another modernizr check foooor...
Modernizr.addTest('textstroke', function () {
var h1 = document.createElement('h1');
if (!('webkitTextStroke' in h1.style) && !('textStroke' in h1.style)) {
return false;
} else
{
return true;
}
});
document.addEventListener("DOMContentLoaded", () => {
let bind = false;
let text = null;
// Must-haves
if (!Modernizr.audio || !Modernizr.cssanimations || !Modernizr.textshadow) {
text = document.getElementsByClassName("intro-text--cant")[0];
}
// Should-haves
else if (!Modernizr.textstroke) {
bind = true;
text = document.getElementsByClassName("intro-text--shouldnt")[0];
}
// All good!
else {
bind = true;
text = document.getElementsByClassName("intro-text--can")[0];
}
text.className += " intro-text--show";
if (bind) {
const btns = document.querySelectorAll("[data-play]");
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", () => {
start();
});
}
}
});
// Fade out intro, start music and animation
let started = false;
function start() {
if (started) {
return;
}
started = true;
const intro = document.getElementsByClassName("intro")[0];
const music = new Audio("StrangerThings.mp3");
intro.className += " intro--hide";
music.addEventListener("canplay", () => {
setTimeout(() => {
startAnimation();
setTimeout(() => {
music.play();
}, 200);
}, 1500);
});
}
// Kick off the animation
function startAnimation() {
// In milliseconds, how long each one is
const creditsMs = 3000;
const scenesMs = [
creditsMs,
creditsMs * 2,
creditsMs,
creditsMs,
creditsMs,
creditsMs,
creditsMs * 2,
19500];
// Elements
const viewport = document.getElementsByClassName("viewport")[0];
const letterbox = document.getElementsByClassName("letterbox")[0];
const scenes = document.getElementsByClassName("title--scene");
const fullTitle = document.getElementsByClassName("title--full")[0];
const credits = document.getElementsByClassName("credits-group");
const finalCredit = document.getElementsByClassName("credits-final")[0];
viewport.className += " viewport--show";
letterbox.className += " letterbox--show";
// Set up credits to show every interval
let activeCredits = null;
for (let i = 0; i < credits.length; i++) {
setTimeout(() => {
if (credits[i - 1]) {
credits[i - 1].className = "credits-group";
}
credits[i].className = "credits-group credits-group--show";
}, i * creditsMs);
if (!credits[i + 1]) {
setTimeout(() => {
credits[i].className = "credits-group";
}, i * creditsMs + creditsMs);
}
}
// Set up scenes to show after each interval
let offset = 0;
for (let i = 0; i < scenes.length; i++) {
setTimeout(() => {
if (scenes[i - 1]) {
scenes[i - 1].className = scenes[i - 1].
className.replace("title--show", "");
}
scenes[i].className += " title--show";
}, offset);
offset += scenesMs[i];
if (!scenes[i + 1]) {
// Show the last scene
setTimeout(() => {
scenes[i].className = scenes[i].className.replace("title--show", "");
fullTitle.className += " title--show";
}, offset);
// Show the final credits
setTimeout(() => {
finalCredit.className += " credits-group--show";
}, offset + scenesMs[i + 1] + 1500);
}
}
}