Skip to content

Commit d1e0e45

Browse files
committed
Added color-picker
1 parent 482b4ad commit d1e0e45

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

Minimal/LightSaber/assets/style.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,67 @@ body {
113113
.T404 h1 {
114114
font-size: 5.5em;
115115
}
116+
}
117+
118+
/* color-picker */
119+
.color-picker {
120+
position: absolute;
121+
left: -50px;
122+
width: 50px;
123+
height: 100%;
124+
background: #0f0f0f;
125+
border-radius: 0 0.8rem 0 0;
126+
display: flex;
127+
flex-direction: column;
128+
justify-content: space-evenly;
129+
align-items: center;
130+
box-shadow: var(--LightSaber-color) 0 0 20px;
131+
z-index: 2;
132+
transition: 200ms linear;
133+
}
134+
135+
.color-picker.show {
136+
left: 0;
137+
}
138+
139+
.show-btn {
140+
position: absolute;
141+
width: 40px;
142+
height: 20px;
143+
right: -20px;
144+
bottom: 0;
145+
z-index: -1;
146+
border-radius: 5px;
147+
background: #0f0f0f;
148+
color: #fff;
149+
display: flex;
150+
justify-content: flex-end;
151+
align-items: center;
152+
cursor: pointer;
153+
}
154+
155+
.show-btn span {
156+
margin-right: 6px;
157+
transition: 200ms linear;
158+
}
159+
160+
.color-picker.show .show-btn span {
161+
transform: rotateZ(180deg);
162+
}
163+
164+
.color-picker .color {
165+
width: 40px;
166+
height: 40px;
167+
border: #fff 3px solid;
168+
border-radius: 50%;
169+
cursor: pointer;
170+
transition: 200ms linear;
171+
}
172+
173+
.color-picker .color.active {
174+
border: #555 3px solid;
175+
}
176+
177+
.color-picker .color:hover:not(.active) {
178+
border: #999 3px solid;
116179
}

Minimal/LightSaber/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,48 @@
1515
<h1>4X4</h1>
1616
</section>
1717

18+
<section id="color_picker" class="color-picker">
19+
<div class="color active" style="background-color: var(--Green)"></div>
20+
<div class="color" style="background-color: var(--Blue)"></div>
21+
<div class="color" style="background-color: var(--red)"></div>
22+
<div class="color" style="background-color: var(--pruple)"></div>
23+
<div class="color" style="background-color: var(--Pink)"></div>
24+
<div class="color" style="background-color: var(--orange)"></div>
25+
<div class="color" style="background-color: var(--yellow)"></div>
26+
<div class="color" style="background-color: var(--white)"></div>
27+
<div class="color" style="background-color: var(--black)"></div>
28+
<div id="show_btn" class="show-btn"><span> > </span></div>
29+
</section>
30+
1831
<!--Script-->
1932
<script type="text/javascript">
2033
let LightSaber = document.getElementById("LightSaber");
2134
if (window.outerHeight > window.outerWidth) {
2235
LightSaber.classList.add("Second")
2336
LightSaber.style.width = window.outerHeight + "px"
2437
}
38+
39+
/* color-picker */
40+
let color_picker = document.getElementById("color_picker");
41+
let colors = document.getElementsByClassName("color");
42+
let show_btn = document.getElementById("show_btn");
43+
show_btn.onclick = () => {
44+
color_picker.classList.toggle("show")
45+
}
46+
for (let i = 0; i < colors.length; i++) {
47+
colors[i].addEventListener("click", () => {
48+
for (let g = 0; g < colors.length; g++) {
49+
colors[g].className = "color";
50+
}
51+
colors[i].className = "color active";
52+
document.querySelector(':root').style.setProperty('--LightSaber-color', colors[i].style.backgroundColor);
53+
let animationName = getComputedStyle(LightSaber).animationName;
54+
LightSaber.style.animationName = "none";
55+
setTimeout(function () {
56+
LightSaber.style.animationName = animationName;
57+
}, 100);
58+
})
59+
}
2560
</script>
2661
</body>
2762
</html>

0 commit comments

Comments
 (0)