-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_bg.js
175 lines (145 loc) · 4.39 KB
/
script_bg.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
// note - look how when selecting a class its the same as when you select it in
// a css file .style
// These two bellow select the class names color1 and 2
// var color1= document.querySelector(".color1");
// var color2= document.querySelector(".color2");
// This selects the header h3 * there is only one h3 in the doc so its ok for this instance
// I could otherwise call give it a id
// var css = document.querySelector("h3");
// This selects the the body with the id "gradient"
// var body = document.querySelector("body");
// This function is created to avoid repeating myself in two listeners
// function getinput (){
// // Here I am setting the body css style property for background
// body.style.background =
// // This is the Linear- gradient function
// // and can go in any direction, change tilt deg and amount for each color
// // Here i am inserting my var's + .value for inputs
// "linear-gradient(50deg , "
// + color1.value
// // note - to space the syntax and write in what i want i need to add string commas
// // the vars dont use them because they are not string
// + ", "
// + color2.value
// + ")";
// To add the gradient values to the body background in text we can
// add another way of inserting text by adding .textContent
// So - Add the body.style.background from above to css which is <h3>
// and add on the string ; so that you can copy and paste directly from the scree to your css file.
// css.textContent = body.style.background + ";";
// }
// MY MESS AROUND CREATION ⬇
// Below is my first attemt at using browserify/.json file/lodash
var _ = require('lodash');
var array = [1,2,3,4,5,6,7,8,9];
// Then console log the string 'answer' run the method from lodash .without where the first parameter
// is the array and the second parameter is what we're leaving out of it (without 3)
console.log('answer:', _.without(array, 3))
// //
var color1 = document.getElementById("color1");
var color2 = document.getElementById("color2");
var color3 = document.getElementById("color3");
var css = document.querySelector("h3");
var body = document.querySelector("body");
var input = document.getElementById("userinput");
var button = document.getElementById("enter");
var col = false;
var but = document.getElementById("but")
function displayStyle(){
css.textContent = body.style.background + ";";
}
function inputLength() {
return input.value.length;
}
// This was just so i could get some experience with the includes method
// function includesdeg() {
// if (inputLength() > 0 && input.value.includes("deg"))
// return true;
// }
function changeTiltAfterClick() {
if (col === true) {
thirdcolour();
}
else if (col === false) {
getinput();
}
}
function changeTiltAfterKeypress(event) {
if (col === true && event.keyCode === 13){
thirdcolour();
}
else if(col === false && event.keyCode === 13){
getinput();
}
}
// This IS A GAME CHANGER!!! Really opened my eyes to alot of problems i was trying to solve
// Every time that this function is run it changes the value of col to true or false
// So now i can toggle my button and let other functions run off of this statement aswell
function isit(){
col = !col;
console.log(col);
itis();
}
function itis(){
if (col ===true){
thirdcolour();
}
else if(col === false){
getinput();
}
}
function getinput (){
if (input.value.length < 1){
body.style.background =
"linear-gradient(50deg, "
+ color1.value
+ ", "
+ color2.value
+")";
displayStyle();
}
else {
body.style.background =
"linear-gradient( "
+input.value.trim()
+"deg, "
+ color1.value
+ ", "
+ color2.value
+")";
displayStyle();
}
}
function thirdcolour (){
if (col === true && input.value.length < 1){
body.style.background =
"linear-gradient(50deg, "
+ color1.value
+ ", "
+ color2.value
+","
+ color3.value
+")";
displayStyle();
}
else if( col === true){
body.style.background =
"linear-gradient( "
+input.value.trim()
+"deg, "
+ color1.value
+ ", "
+ color2.value
+","
+ color3.value
+")";
displayStyle();
}
}
color1.addEventListener("input", itis );
color2.addEventListener("input", itis );
button.addEventListener("click", changeTiltAfterClick);
input.addEventListener("keypress", changeTiltAfterKeypress);
color3.addEventListener("input", thirdcolour);
but.addEventListener("click", isit);
// if the third color button is pressed then add in a third color