Skip to content

Instantly share code, notes, and snippets.

@amirkhiz
Last active December 24, 2018 13:25
Show Gist options
  • Save amirkhiz/46bd6b0502ca325a44f47386eef88621 to your computer and use it in GitHub Desktop.
Save amirkhiz/46bd6b0502ca325a44f47386eef88621 to your computer and use it in GitHub Desktop.
Calculate circle progress for css gradient values in javascript
let step = 1;
let loop = Math.round(100 / step);
let increment = 360 / loop;
let half = Math.round(loop / 2);
let nextDeg = 0;
for (let i = 0; i <= loop; i += step) {
if (i < half) {
nextDeg = 90 + increment * i;
// background-image linear-gradient(90deg, $back-color 50%, transparent 50%, transparent), linear-gradient(nextDeg, $theme-color 50%, $back-color 50%, $back-color)
console.log('Progress:', i * step, 'First:', 90, 'Second:', nextDeg);
} else {
nextDeg = -90 + increment * (i - half);
// background-image linear-gradient(nextDeg, $theme-color 50%, transparent 50%, transparent), linear-gradient(270deg, $theme-color 50%, $back-color 50%, $back-color)
console.log('Progress:', i * step, 'First:', nextDeg, 'Second:', 270);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment