Skip to content

Instantly share code, notes, and snippets.

@bwindels
Last active October 7, 2019 08:13
Show Gist options
  • Save bwindels/e10909e20d132ef2ec33527f3b62ec1d to your computer and use it in GitHub Desktop.
Save bwindels/e10909e20d132ef2ec33527f3b62ec1d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
body {
--size: 128px;
--fg-color: blue;
--progress: 0;
}
@keyframes rotate {
from { transform: rotate(0); }
to { transform: rotate(360deg); }
}
.progress {
animation-name: rotate;
animation-duration: 4s;
animation-iteration-count: infinite;
}
.progress {
width: var(--size);
height: var(--size);
}
.progress circle {
fill:none;
stroke: var(--fg-color);
stroke-width: calc(var(--size) * 0.1);
stroke-linecap: round;
stroke-dasharray: var(--progress) 1;
}
</style>
</head>
<body>
<svg class="progress" viewBox="0 0 100% 100%">
<circle cx="50%" cy="50%" r="45%" pathLength="1"></circle>
</svg>
<script type="text/javascript">
const values = [0, 0.1, 0.2, 0.22, 0.27, 0.3, 0.4, 0.5, 0.6, 0.7, 0.7, 0.7, 0.8, 0.85, 0.9, 0.9, 0.95, 0.99, 1 ];
let index = -1;
let forward = true;
setInterval(() => {
index += forward ? 1 : -1;
if (index < 0 || index >= values.length) {
forward = !forward;
index += forward ? 1 : -1;
}
document.body.style.setProperty("--progress", values[index]);
}, 200);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment