-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradientGenerator.html
More file actions
229 lines (200 loc) · 7.16 KB
/
GradientGenerator.html
File metadata and controls
229 lines (200 loc) · 7.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;600&display=swap" rel="stylesheet">
<title>Gradient Generator</title>
<style>
*,
*::before,
*::after {
padding: 0;
margin: 0;
box-sizing: border-box;
border: none;
outline: none;
}
body {
height: 100vh;
}
.container {
background-color: #fff;
width: 400px;
padding: 50px 30px;
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
border-radius: 10px;
box-shadow: 0 20px 25px rgba(0, 0, 0, 0.25);
}
.container *:not(i) {
font-family: 'Rubik', sans-serif;
}
.colors {
width: 100%;
display: flex;
justify-content: space-around;
}
input[type="color"] {
appearance: none;
-webkit-appearance: none;
background-color: transparent;
width: 100px;
height: 45px;
cursor: pointer;
}
input[type="color"]::-webkit-color-swatch {
border-radius: 20px;
border: none;
}
.buttons {
width: 100%;
display: flex;
justify-content: space-between;
margin: 30px 0;
}
.buttons button {
height: 35px;
width: 35px;
background-color: transparent;
border: 2px solid #d5d5dc;
border-radius: 5px;
cursor: pointer;
}
.rotate-icon i {
transform: rotate(45deg);
}
.buttons .active {
border: none;
background-color: #4a6ee0;
color: #fff;
}
#submit {
display: block;
background-color: #4a6ee0;
color: #fff;
font-size: 16px;
padding: 12px 70px;
border-radius: 25px;
margin: 0 auto 30px auto;
cursor: pointer;
}
#reset {
display: block;
background-color: #4a6ee0;
color: #fff;
font-size: 16px;
padding: 12px 70px;
border-radius: 25px;
margin: 17px auto 30px auto;
cursor: pointer;
}
.output {
background-color: #f0f2fc;
}
#code {
width: 100%;
resize: none;
color: #30304a;
padding: 10px 20px;
background-color: transparent;
}
#copy {
font-size: 14px;
background-color: #4a6ee0;
color: #fff;
position: relative;
left: 85%;
bottom: 10px;
border-radius: 3px;
padding: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="colors">
<input type="color" id="color-a" value="#7986cb">
<input type="color" id="color-b" value="#1a237e">
</div>
<div class="buttons">
<button id="direction1" disabled onclick="setDirection('to top', this)">
<i class="fas fa-arrow-up"></i>
</button>
<button id="direction2" class="active" disabled onclick="setDirection('to bottom', this)">
<i class="fas fa-arrow-down"></i>
</button>
<button id="direction3" disabled onclick="setDirection('to right', this)">
<i class="fas fa-arrow-right"></i>
</button>
<button id="direction4" disabled onclick="setDirection('to left', this)">
<i class="fas fa-arrow-left"></i>
</button>
<button id="direction5" class="rotate-icon" disabled onclick="setDirection('to top right', this)">
<i class="fas fa-arrow-up"></i>
</button>
<button id="direction6" class="rotate-icon" disabled onclick="setDirection('to bottom left', this)">
<i class="fas fa-arrow-down"></i>
</button>
<button id="direction7" class="rotate-icon" disabled onclick="setDirection('to bottom right', this)">
<i class="fas fa-arrow-right"></i>
</button>
<button id="direction8" class="rotate-icon" disabled onclick="setDirection('to top left', this)">
<i class="fas fa-arrow-left"></i>
</button>
</div>
<button id="submit" onclick="generateCode()">Generate</button>
<div class="output">
<textarea id="code" rows="2" readonly></textarea>
<button id="copy" onclick="copyText()">Copy</button>
</div>
<button id="reset" onclick="reset()">Reset</button>
</div>
<script>
let colorOne = document.getElementById("color-a");
let colorTwo = document.getElementById("color-b");
let currentDirection = 'to bottom';
let outputCode = document.getElementById("code");
// Disable all direction buttons initially
let directionButtons = document.querySelectorAll(".buttons button");
directionButtons.forEach(button => button.disabled = true);
function setDirection(value, _this) {
let direcrtions = document.querySelectorAll(".buttons button");
for (let i of direcrtions) {
i.classList.remove("active");
}
_this.classList.add("active");
currentDirection = value;
generateCode(); // Call generateCode here so it updates immediately when direction changes
}
function generateCode() {
let color1 = colorOne.value;
let color2 = colorTwo.value;
outputCode.value = `background-color: linear-gradient(${currentDirection}, ${color1}, ${color2})`;
document.getElementsByTagName("BODY")[0].style.backgroundImage = `linear-gradient(${currentDirection}, ${color1}, ${color2})`;
// Enable direction buttons after generate is clicked
directionButtons.forEach(button => button.disabled = false);
}
function copyText() {
outputCode.select();
document.execCommand('copy');
alert("Gradient Copied!");
}
function reset() {
colorOne.value = "#00000";
colorTwo.value = "#00000";
outputCode.value = "background-color:";
document.getElementsByTagName("BODY")[0].style.backgroundImage = ""; // Remove background color
// Disable direction buttons again after reset
directionButtons.forEach(button => button.disabled = true);
}
// Initially, call generateCode() to show the default gradient
generateCode();
</script>
</body>
</html>