<p class="rgb"></p>
<div class="main">
<div class="div">
<div class="dot"></div>
<div class="bar">
</div>
</div>
</div>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.rgb {
margin-bottom:2px;
text-align: center;
box-shadow: 0 1px 1px black;
padding: 1rem;
justify-content: center;
font-weight: bold;
height: 6vh;
font-size: 1.2rem;
transition: color 0.3s ease-in, font-size 0.3s ease-in;
}
.main {
height: 94vh;
display: grid;
justify-content: center;
align-items: center;
background-color: #282828;
transition: background-color 0.3s ease;
}
.div {
display: flex;
background: #404040;
height: 10px;
width: 400px;
cursor: pointer;
position: relative;
opacity: 1;
border-radius: 2px;
box-shadow: 0 1px 3px black;
}
.div:hover .dot {
opacity: 1;
}
.bar {
height: 100%;
z-index: 1;
position: absolute;
content: "";
top: 0;
transition: background-image 0.2s ease-in;
}
.div:hover .bar {
background-image: linear-gradient(rgb(0, 255, 55), rgb(115, 255, 0));
}
.dot {
opacity: 0;
width: 15px;
height: 15px;
border-radius: 50%;
z-index: 120;
margin-left: -2px;
margin-top: -3px;
left: 0;
position: absolute;
content: "";
top: 0;
background-color: rgba(253, 253, 253, 0.897);
transition: opacity 0.2s ease-out;
}
.dot::before {
width: 3px;
height: 40px;
content: "";
z-index: 0;
top: 14px;
left: 5px;
position: absolute;
background-color: rgb(0, 0, 0);
animation: move 1s both;
animation-iteration-count: infinite;
animation-delay: 1s;
}
@keyframes move {
0% {
opacity: 0.2;
transform: translateX(1%);
background: rgb(60, 255, 0);
}
50% {
opacity: 0.8;
transform: translateY(10%);
background: #ccc;
}
100% {
opacity: 1;
background: rgb(255, 255, 255);
transform: translateY(100%);
}
}
var div = document.querySelector(".div");
var bar = document.querySelector(".bar");
var dot = document.querySelector(".dot");
var main = document.querySelector(".main");
var rgb = document.querySelector(".rgb");
let move;
div.addEventListener("mousedown", MouseDown);
document.addEventListener("mousemove", moveMouse);
function moveMouse(e) {
if (move) {
MouseDown(e);
}
}
function MouseDown(e) {
let percentage;
move = true;
let j = e.clientX - div.offsetLeft;
percentage = (100 * j) / div.clientWidth;
bar.style.backgroundColor = "#b3b3b3";
if (percentage > 100) {
percentage = 100;
}
if (percentage < 0) {
percentage = 0;
}
bar.style.width = percentage + "%";
dot.style.left = percentage + "%";
let gen = `rgb(${Math.round(Math.random() * 255) + 1},
${Math.round(Math.random() * 255) + 1},${Math.round(Math.random() * 255) +
1})`;
rgb.style.color = gen;
rgb.textContent = gen;
main.style.backgroundColor = gen;
}
document.addEventListener("mouseup", e => {
move = false;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.