Javascript variable syntax
In my code:
color = '31,0,0';
grd.addColorStop(0.1,'rgba(31,0,0,0.3)');
How do I replace 31,0,0 with the variable color? I've tried:
开发者_开发百科grd.addColorStop(0.1,'rgba('+color+',0.3)');
but got errors with that or any other combination I've tried.
Thanks!
This works fine in my console, but maybe there is some problems with numbers and strings or something.
To avoid that, you could try this too:
grd.addColorStop( 0.1, ['rgba(', color, ', 0.3)'].join('') );
精彩评论