D
D
Danil Zinchenko2021-02-02 16:10:09
css
Danil Zinchenko, 2021-02-02 16:10:09

How do I convert a CSS gradient (as a string) to a javascript object?

Hi all.
I'm asking for help.

The task is this:
you need to fill the SVG path elements with a gradient.

I get the color of the gradient as a string:

linear-gradient(49.59deg, #165953 -40.47%, rgba(22, 89, 83, 0.24) 98.51%)


And from this I need to make a gradient in SVG. I tested it with pens, it works, it remains only to automate this process, because the gradient will come in the form of a CSS value.

Output pseudo-object (for linear gradient):
{
  angle: "rotate(49.59)",
  stop_1: {
    color: "#165953",
    offset: "-40.47%",
  },
  stop_2: {
    color: "rgba(22, 89, 83, 0.24)",
    offset: "98.51%",
  }
}


Who knows better solutions, better ideas?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question