开发者

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('') );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜