I stumbled upon this amazing progress ring by Matěj Husák and I have a vision to incorporate an image inside the ring as shown:
https://i.sstatic.net/MeSeK.png
Here is the original code:
const circle = document.querySelector('.ring-circle');
const radius = circle.r.baseVal.value;
const circumference = radius * 2 * Math.PI;
circle.style.strokeDasharray = `${circumference} ${circumference}`;
circle.style.strokeDashoffset = circumference;
function setProgress(percent) {
const offset = circumference - percent / 100 * circumference;
circle.style.strokeDashoffset = offset;
}
function setProgressFromButton() {
setProgress(document.getElementById("input-percent").value);
}
setProgress(10);
body, html {
margin: 0;
background-color: #2D132C;
height: 100%;
font-family: Sanchez, sans-serif;
color: white;
}
h1 {
margin: 0px;
margin-bottom: 24px;
font-size: 24px;
text-align: center;
font-weight: 100;
}
button:active {
outline: none;
}
button:focus {
outline: none;
}
.container {
width: 350px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.button-start {
font-family: Sanchez;
font-style: normal;
font-weight: normal;
font-size: 16px;
line-height: 20px;
text-align: center;
color: #FFFFFF;
padding: 6px 26px;
border: none;
display: block;
margin-left: auto;
margin-right: auto;
display: inline-block;
border-bottom: 4px solid #C72C41;;
background: #EE4540;
cursor: pointer;
vertical-align: top;
transition: 250ms ease;
}
.button-start:hover {
background: #EE342F;
}
.button-start:active {
border-bottom: none;
}
h1 {
margin-bottom: 0px;
}
.ring {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 40px;
margin-top: 40px;
transform: rotate(90deg);
}
.ring-circle {
stroke-dasharray: 10 20;
transition: stroke-dashoffset 0.60s ease;
}
#input-percent {
width: 121px;
height: 30px;
background: #881238;
border:none;
border-bottom: 4px solid #660B28;
vertical-align: top;
margin-top: 2px;
padding-right: 8px;
color: white;
font-family: Sanchez;
font-style: normal;
font-weight: normal;
font-size: 16px;
line-height: 20px;
text-align: center;
text-align: right;
}
.input-wrapper {
width: max-content;
margin-left: auto;
margin-right: auto;
display: block;
}
input:active {
outline: none;
}
input:focus {
outline: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>The progress ring</title>
<link href="https://fonts.googleapis.com/css?family=Sanchez&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<h1 id="main-header">The progress ring.</h1>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/18320/profile/profile-512.jpg?3"/>
<svg class="ring" height="200" width="200">
<circle stroke-width="18" stroke="#801336" fill="transparent" r="84" cx="100" cy="100"/>
<circle class="ring-circle" stroke-width="18" stroke="#EE4540" fill="transparent" r="84" cx="100" cy="100"/>
</svg>
<div class="input-wrapper">
<input id="input-percent" value="10" type="text" name="" id="">
<button onclick="setProgressFromButton()" id="confirm-button" class="button-start">Ok</button>
</div>
</div>
</body>
</html>
The challenge lies in using SVG for the ring and facing difficulties incorporating the image within the circle without affecting other elements.