I am not on my laptop to test this, but I wonder if we can use a CSS Custom Property for the color part of a gradient and animate its value depending on where in the page you are.
Take a look at this example from a few years ago that highlights how you can do this: