开发者

Javascript variable syntax

开发者 https://www.devze.com 2023-02-05 11:56 出处:网络
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:

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

精彩评论

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