How do I create a linear gradient as a JavaScript property value?

40 views Asked by At

Is it possible to set a linear gradient as a property value? I only know how to a hex value to the property, but how would you do the gradient equivalent of a CSS value in a JavaScript property value?

CSS

background: linear-gradient(180deg, #FAF9FA 0%, #F2F5FE 65.75%);

JavaScript to add a gradient to the background property.

this.opts = {
  background: 0x000000,
  fill: 0xffffff,
  ...options,
};
1

There are 1 answers

0
Nokkond On BEST ANSWER

Have you tried to implement it like this?

this.opts = {
  background: 'linear-gradient(180deg, #FAF9FA 0%, #F2F5FE 65.75%)',
  ...options,
};