-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicJS.js
More file actions
237 lines (205 loc) · 7.93 KB
/
dynamicJS.js
File metadata and controls
237 lines (205 loc) · 7.93 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
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
$(document).ready(function()
{
//Variables for DOM and overall flow
var clickCount = -1;
var $top = $("#top");
var $button = $("#button");
var $div = $("#response");
//Variables for animation function
var button = document.getElementById('button');
const maxXPosition = window.innerWidth - 102;
var speedX = 10;
//important click counts
var key1 = 18;
var key2 = 22;
var key3 = 24;
var key4 = 25;
var key5 = 26;
var key6 = 27;
var key7 = 28;
var key8 = 29;
var key9 = 47;
//All responses
var responses = ["Why did you push the button?", "You pushed it again?", "Ok stop pushing it.", "I'm serious.",
"Ok you really need to stop pusing the button.", "If you push it again your computer will crash.",
"Ok it was only a threat, just please stop.", "I asked nicely.", "Fine. . . Have it your way", "", "",
"", "You're still clicking?", "You've got to be kidding me.", "ERROR", "I know you can read. Didn't you see the ERROR?",
"You're annoying me at this point.", "Two can play at this game.","I'll give you one more chance. . .",,
"You're still going to click a blue button?", "Wow", "Just wow. . .",,"No worries, I have plenty of tricks up my sleeve.",
"How about now. . .", "No way you push it now.", "You're good.", "Try and find it now. (Hint: Hover)", "I give up.",, "You win.",
"But you have to at least hear my story:", "There once was an old empty house.",
"In this house was nothing but a cardboard box.", "Within this cardboard box was a simple black briefcase.",
"Written on the briefcase were some simple words.", "DO NOT OPEN", "Do you want to know what's inside?",
"I'm sure you do.", "Well I will tell you.", "Inside is a button. . .", "A red button.", "But not just any red button. . .",
"THE BIG RED BUTTON", "And next to THE BIG RED BUTTON is a note.", "A note that says something very important.",
"The note says. . ."];
$button.click(function()
{
//Some clicks call special function, otherwise a click just moves to the next response
if (clickCount == key1)
{
blue();
clickCount++;
}
else if (clickCount == key2)
{
red();
clickCount++;
}
else if (clickCount == key3)
{
small();
clickCount++;
}
else if (clickCount == key4)
{
move();
clickCount++;
}
else if (clickCount == key5)
{
moving();
clickCount++;
}
else if (clickCount == key6)
{
stop();
clickCount++;
}
else if (clickCount == key7)
{
chaos();
clickCount++;
}
else if (clickCount == key8)
{
undo();
clickCount++;
}
else if (clickCount == key9)
{
$div.empty();
$div.append('<h3 id="text" class="center">Do NOT press THE BIG RED BUTTON.</h3>');
clickCount = -1;
}
else
{
clickCount++;
$div.empty();
$div.append('<h3 id="text" class="center">' + responses[clickCount] + '</h3>');
console.log(clickCount);
}
});
//Turns the title and button blue
function blue()
{
$top.empty();
$top.append('<h1 id="blueTitle" class="center buttonBorder">THE BIG BLUE BUTTON</h1>');
document.getElementById("button").id = "blue";
$div.empty();
$div.append('<h3 id="text" class="center">Boom. Look at that, now it\'s blue.</h3>');
}
//Turns the title and button back to red
function red()
{
$top.empty();
$top.append('<h1 id="title" class="center buttonBorder">THE BIG RED BUTTON</h1>');
document.getElementById("blue").id = "button";
$div.empty();
$div.append('<h3 id="text" class="center">Okay, so the Blue Button didn\'t faze you.</h3>');
}
//Makes the button very small
function small()
{
$top.empty();
$top.append('<h1 id="smallTitle" class="center buttonBorder">THE SMALL RED BUTTON</h1>');
$button.addClass("small");
$div.empty();
$div.append('<h3 id="text" class="center">Try and click it now. . .</h3>');
}
//Moves the small button
function move()
{
$button.removeClass("center").addClass("move");
$div.empty();
$div.append('<h3 id="text" class="center">' + responses[clickCount] + '</h3>');
}
//Makes the button normal sized and calls the animation function loop
function moving()
{
$top.empty();
$top.append('<h1 id="title" class="center">THE BIG RED BUTTON</h1>');
$button.removeClass("move small").addClass("center");
$div.empty();
$div.append('<h3 id="text" class="center">' + responses[clickCount] + '</h3>');
var positionX = 102;
loop(positionX);
}
//Animates button to move side to side across the screen.
function loop(positionX)
{
//Animation function below was based off function from: http://www.codeblocq.com/2016/05/Two-Ways-of-Creating-an-Animation-Loop-in-JavaScript/
function step()
{
positionX = positionX + speedX;
if (positionX > maxXPosition || positionX < 102)
{
speedX = speedX * (-1);
}
button.style.left = positionX + 'px';
if (clickCount == 28)
{
return -1;
}
else
{
window.requestAnimationFrame(step);
}
}
if(clickCount == 28)
{
return -1;
}
else
{
window.requestAnimationFrame(step);
}
}
//Called after the animation has stopped
function stop()
{
$div.empty();
$div.append('<h3 id="text" class="center">' + responses[clickCount] + '</h3>');
}
//Changes background red, making the button invisible. Adds classes to the button to make it visible on mouseover
function chaos()
{
$top.empty();
$top.append('<h1 id="blackTitle" class="center">THE INVISIBLE BUTTON</h1>');
$div.empty();
$div.append('<h3 id="text" class="center">' + responses[clickCount] + '</h3>');
$("*").css("background-color", "red");
$button.removeClass("center").addClass("invisible otherMove");
$button.removeAttr("style");
$button.hover(function ()
{
$button.removeClass("invisible").addClass("buttonBorder");
}, function(){
$button.removeClass("buttonBorder").addClass("invisible");
});
}
//Undoes the chaos function resetting everything back to normal
function undo()
{
$("*").removeAttr("style");
$button.removeClass("invisible otherMove").addClass("center");
$button.hover(function ()
{
$button.removeClass("invisible").addClass("buttonBorder");
});
$top.empty();
$top.append('<h1 id="title" class="center">THE BIG RED BUTTON</h1>');
$div.empty();
$div.append('<h3 id="text" class="center">' + responses[clickCount] + '</h3>');
}
});