I want to put a simple loading indicator on my website that is triggered by a script. It should be a simple arc with a gradient and rotate while the user waits. I haven't tried the animation part yet, but am stuck on static styles now. This is what I've got so far:
It draws the arc counterclockwise from the top edge to the right edge (270°), but the gradient is wrong. The final image of the arc stroke is colored from left to right in screen space, rather than following the path such that the start point (top edge, 0°) is opaque and the end point (right edge, 270°) is transparent.
How do I make the gradient follow my arc path?
Mike Bostock found a way, although it's not easy:https://bl.ocks.org/mbostock/4163057
Basically, this technique uses
getPointAtLength
To split a stroke into many short strokes, specify an interpolation color stop for each stroke, and then interpolate the Apply gradient with each short stroke.Good luck if you're up to the challenge ;)
Editor (July 3, 2019):
Now there is a library that can help you do exactly what you are looking for.Not required to use D3, but you can if you wish.This is a tutorial about Medium.
CSS Image Module - Level 4 introducesconic-gradient. According to MDN,Supportedin all major browsers except IE.
Although it's not technically a gradient along the path, since your path is circular, you can achieve the desired result by: