<img src="//www.w3cplus.com/sites/default/files/blogs/2022/2207/avatar.svg" alt="">
<div class="gradient"></div>
<div class="target"></div>
<div class="source">
<img src="//www.w3cplus.com/sites/default/files/blogs/2022/2207/avatar.svg" alt="">
<div class="gradient"></div>
</div>
<div class="form">
<label for="opacity">--opacity:</label>
<input type="range" min="0" max="100" step="1" value="30" name="opacity" id="opacity">
<output id="opacity-output">30%</output>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: #557;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
gap: 1rem;
padding: 1rem;
place-content: center;
}
body > * {
width: 100%;
}
img {
display: block;
aspect-ratio: 3 / 4;
}
.gradient {
aspect-ratio: 3 / 4;
background-image: linear-gradient(to bottom, #09f, #90f);
}
:root {
--opacity: 30%;
}
.target {
aspect-ratio: 3 / 4;
background-image: -webkit-cross-fade(
url("//www.w3cplus.com/sites/default/files/blogs/2022/2207/avatar.svg"),
linear-gradient(to bottom, #09f, #90f),
var(--opacity)
);
background-size: 100% 100%;
}
.source {
position: relative;
aspect-ratio: 3 / 4;
}
.source > * {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.source > img {
z-index: 1;
width: 100%;
height: 100%;
}
.source > .gradient {
z-index: 2;
opacity: var(--opacity);
}
.form {
padding: 1rem;
background-color: rgb(0 0 0 / 0.6);
backdrop-filter: blur(20px);
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
color: #fff;
z-index: 99;
}
.form input {
width: 32px;
outline: none;
border: none 0;
font-family: "Exo", Arial, sans-serif;
background-color: transparent;
}
.form label {
line-height: 1;
display: inline-flex;
align-items: center;
}
input[type="range"] {
width: min(200px, 10vh);
}
const rootElement = document.documentElement;
const inputHander = document.getElementById("opacity");
const outPut = document.getElementById("opacity-output");
inputHander.addEventListener("input", (etv) => {
rootElement.style.setProperty("--opacity", `${etv.target.value}%`);
outPut.textContent = `${etv.target.value}%`;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.