Updating linear gradient using JavaScript (React)
Is there a simple way to update a linear gradient background using javascript? Right now i have it like this in my CSS:
and the idea is to update the
--bg-gradient
var to any valid gradient string that i take in from user input. this was my initial idea:
But nothing happens when this function runs - the variable isn't updated. I'm guessing it can't parse the string as a linear-gradient function or whatnot? I saw this but that looks like a hassle: https://www.w3schools.com/tags/canvas_createlineargradient.asp. Is there any other way? Seems like a simple problem4 Replies
hmm but when I tested that code it does work though?
Is there any other element at play that might make it not work here?
oh it seems like it breaks if there is an ending
;
to the string...works without it 🙂
some extra parsing logic to accept more formats and it works as expected 👍