-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_picker.html
108 lines (95 loc) · 3.1 KB
/
color_picker.html
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
<!DOCTYPE html>
<html>
<head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(to right, #bdc3c7, #2c3e50);
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.colorPickerContainer {
background: #ffffff;
padding: 30px;
border-radius: 15px;
box-shadow: 0px 10px 30px -5px rgba(0, 0, 0, 0.3);
text-align: center;
}
label {
font-size: 1.2em;
font-weight: 600;
}
#colorPicker {
display: block;
margin: 20px auto;
padding: 10px;
border: none;
border-radius: 10px;
}
#selectedColor {
margin-top: 20px;
}
#colorHexValue {
font-size: 1.1em;
font-weight: 600;
color: #333;
margin-top: 10px;
}
#colorDisplay {
height: 50px;
width: 50px;
margin: 10px auto;
border-radius: 25px;
}
#copyButton {
padding: 10px 20px;
border: none;
background-color: #2c3e50;
color: white;
border-radius: 10px;
font-weight: 600;
cursor: pointer;
transition: background 0.3s ease;
}
#copyButton:hover {
background-color: #bdc3c7;
}
</style>
</head>
<body>
<div class="colorPickerContainer">
<label for="colorPicker">Select a color:</label>
<input type="color" id="colorPicker">
<div id="selectedColor">
<div id="colorDisplay"></div>
<p id="colorHexValue"></p>
<button id="copyButton">Copy</button>
</div>
</div>
<script>
const colorPicker = document.querySelector("#colorPicker");
const colorHexValue = document.querySelector("#colorHexValue");
const copyButton = document.querySelector("#copyButton");
const selectedColorDiv = document.querySelector("#selectedColor");
const colorDisplay = document.querySelector("#colorDisplay");
selectedColorDiv.style.display = "none"; // Hide at the start
colorPicker.addEventListener("input", function() {
colorHexValue.textContent = "Selected Hex Value: " + colorPicker.value;
colorDisplay.style.backgroundColor = colorPicker.value;
selectedColorDiv.style.display = "block"; // Show the selected color div
});
copyButton.addEventListener("click", function() {
const el = document.createElement('textarea');
el.value = colorPicker.value;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
alert('Copied the color value: ' + colorPicker.value);
});
</script>
</body>
</html>