-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
198 lines (131 loc) · 4.14 KB
/
main.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
window.onload = beginningAnimation();
let color = "";
let psychColor = false;
//animating initial text
function beginningAnimation() {
textAnimate();
const title = document.querySelector(`#title`);
const desc1 = document.querySelector(`#desc1`);
title.classList.remove(`animate`);
desc1.classList.add(`animate`);
textAnimate();
}
function textAnimate() {
let text = document.querySelector(`.animate`);
let strText = text.textContent;
let splitText = strText.split("");
text.textContent = "";
console.log(splitText);
for (let i=0; i < splitText.length; i++) {
text.innerHTML += "<span>"+ splitText[i] + "</span>";
}
//inserting letters one by one
let char = 0;
let timer = setInterval(onTick, 100);
function onTick() {
const span = text.querySelectorAll(`span`)[char];
span.classList.add(`fade`);
char++;
if(char === splitText.length){
complete();
return;
}
}
function complete() {
clearInterval(timer); //does this need to be its own function?
timer = null;
}
}
//Generate grid to size of user input
function createGrid(widthHeight) {
document.getElementById(`grid-container`).innerHTML = "";
for (let i = 0; i < widthHeight; i++) {
let divRow = document.createElement(`div`);
divRow.classList.add(`divRow`);
document.getElementById(`grid-container`).appendChild(divRow);
for (let y = 0; y < widthHeight; y++) {
let divCol = document.createElement(`div`);
divCol.classList.add(`divCol`);
divRow.appendChild(divCol);
divCol.addEventListener(`mouseenter`, function () {
if (psychColor) {
color = `#${randomColor()}`;
}
if (!color) {
color = `black`;
}
this.style.backgroundColor = color;
});
}
}
}
//return the color choosen by the user
function chooseColor() {
let color = document.getElementById(`chooseColor`).value;
console.log(color);
return color;
}
//returns random colors for psychedleic button
function randomColor() {
let randomColor = Math.floor(Math.random() * 16777215).toString(16);
console.log(randomColor);
return randomColor;
}
//black button
document.getElementById(`black-button`).addEventListener(`click`, function () {
psychColor = false;
color = `black`;
});
//psychedlic button selection
document.getElementById(`psych-button`).addEventListener(`click`, function () {
psychColor = true;
});
//eraser button
document.getElementById(`erase-button`).addEventListener(`click`, function () {
psychColor = false;
color = `rgb(228, 228, 228)`;
});
//Choose color button
document.getElementById(`chooseColor`).addEventListener(`input`, function () {
psychColor = false;
color = chooseColor();
}, false);
//reset colors on grid
document.getElementById(`reset-button`).addEventListener(`click`, function () {
resetButton();
});
function resetButton() {
let grid = document.getElementsByClassName(`divCol`);
let gridArray = Array.from(grid);
gridArray.forEach(element => {
element.style.backgroundColor = `rgb(156, 149, 136)`;
});
document.getElementById(`myRange`).value = 25;
createGrid(25);
}
//grid size slider
let slider = document.getElementById(`myRange`);
slider.oninput = function() {
createGrid(this.value);
}
//default grid size
createGrid(25);
//psych-button change color on hover
document.getElementById(`psych-button`).addEventListener(`mouseover`, function () {
console.log(`hello`);
});
function repeatWhileMouseOver(element, action, milliseconds) {
let interval = null;
element.addEventListener('mouseover', function () {
interval = setInterval(action, milliseconds);
});
element.addEventListener('mouseout', function () {
clearInterval(interval);
});
}
function psychBackground() {
let button = document.getElementById(`psych-button`);
button.style.backgroundColor = `#${randomColor()}`;
console.log(button);
}
repeatWhileMouseOver(document.getElementById('psych-button'), psychBackground, 100);