I've been experimenting with setting a radial gradient as the background of a div using JavaScript. My goal is to have the gradient start in the middle with around 0.8 opacity, gradually fading to 0 towards the edges to create a soft fading effect. I've tried a few approaches, but some didn't work at all and others didn't produce the desired result.
One method that partially worked was applying multiple rgba definitions and reducing the opacity by 0.1 at each step:
arrCircleDivs[i].firstChild.style.backgroundImage =
'-webkit-radial-gradient(center,rgba('+r+','+g+','+b+',0.8),
rgba('+r+','+g+','+b+',0.8),rgba('+r+','+g+','+b+',0.8),rgba('+r+','+g+','+b+',0.7),rgba('+r+','+g+','+b+',0.6),rgba('+r+','+g+','+b+',0.5),rgba('+r+','+g+','+b+',0.4),
rgba('+r+','+g+','+b+',0.3),rgba('+r+','+g+','+b+',0.2),
rgba('+r+','+g+','+b+',0.1),rgba('+r+','+g+','+b+',0))';
However, these attempts did not work:
arrCircleDivs[i].firstChild.style.backgroundImage = '-webkit-radial-gradient
(center, circle cover, rgba(30,87,153,0.7) 0%,rgba(30,87,153,0) 100%);
arrCircleDivs[i].firstChild.style.backgroundImage = '-webkit-gradient
(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(30,87,153,0.7)),
color-stop(100%,rgba(30,87,153,0)));
The error message I encountered was:
Uncaught SyntaxError: Unexpected token ILLEGAL
Is there a way to achieve this desired effect using JavaScript?