To create a circle using CSS, you can utilize the ::after pseudo-element and define constant images with CSS variables.
function applyZoom() {
const zoomValue = document.getElementById('sizeinput').value;
const zoom = '--zoom:' + zoomValue + ";"
document.getElementById('myavatar').setAttribute('style', zoom);
}
.mydiv {
--image: url('https://picsum.photos/id/46/300/300');
--size: 400px;
display:grid;
place-items:center;
width:400px;
border-radius: 2rem;
background-image: linear-gradient(rgba(56, 76, 111, 0.5), rgba(56, 76, 111, 0.5)), var(--image);
}
.mydiv, .mydiv::after {
aspect-ratio:1;
background-position: center center;
background-repeat: no-repeat;
background-size: calc(var(--zoom) * var(--size)) calc(var(--zoom) * var(--size));
}
.mydiv::after {
display:block;
content:"";
width:200px;
border:2px solid white;
border-radius:100vh;
background-image: var(--image);
}
<div class='mydiv' id='myavatar' style='--zoom: 1;'>
</div>
<br>
<input id='sizeinput'><button onclick='applyZoom()'>Zoom</button>
Update:
In order to handle image zooming when the zoom value is less than 1, an adjustment is needed by introducing the 'before' element with z-index as shown below:
function applyZoom() {
const circleWidth = 200;
const zoomValue = document.getElementById('sizeinput').value;
document.getElementById('zoomText').textContent = zoomValue;
const zoom = '--zoom:' + zoomValue + ";"
const element = document.getElementById('myavatar');
const containerSize = parseInt(window.getComputedStyle(element).getPropertyValue("--size"));
const resizedImageSize = containerSize * zoomValue;
if(resizedImageSize >= circleWidth) {
element.setAttribute('style', zoom);
}
}
.mydiv {
--image: url('https://picsum.photos/id/46/300/300');
--size: 400px;
position:relative;
overflow: hidden;
display:grid;
place-items:center;
width:400px;
border-radius: 2rem;
background-image: var(--image);
}
.mydiv, .mydiv::after {
aspect-ratio:1;
background-position: center center;
background-repeat: no-repeat;
background-size: calc(var(--zoom) * var(--size)) calc(var(--zoom) * var(--size));
}
.mydiv::before {
display:block;
position: absolute;
content:"";
inset: 0;
width:100%;
background-color: rgba(56, 76, 111, 0.8);
}
.mydiv::after {
display:block;
content:"";
width:200px;
border:2px solid white;
border-radius:100vh;
background-image: var(--image);
z-index: 1;
}
<div class='mydiv' id='myavatar' style='--zoom: 1;'>
</div>
<br>
<input type="range" min="0" max="2" value="1" step="0.1" id="sizeinput" oninput='applyZoom()'>
Zoom: <span id='zoomText'></span>