[英]Create JavaScript element to use in CSS
我正在使用jQuery为我的主页创建一个小的JavaScript API。 在代码的稍后部分,我将通过以下方式将包含css的对象附加到元素:$(element).css(theVariable);
例如,结果应等于以下CSS代码:
h3 { background-color: rgb(0, 80, 0); background-color: rgba(0, 80, 0.75); }
我将如何填充theVariable,以便调用css(theVariable)时的效果与上面的css代码相同? 我不能使用类似
theVariable = {}; theVariable['backgroundColor'] = 'rgb(0, 80, 0)'; theVariable['backgroundColor'] = 'rgba(0, 80, 0, 0,3)';
由于RGBA值将始终覆盖RGB值。
有什么办法可以避免这个问题?
我建议您在JavaScript中执行相反的操作。 您不知道浏览器是否支持rgba ,您可以执行以下操作:
theVariable = {};
theVariable['backgroundColor'] = 'rgba(0, 80, 0, 0,3)';
if(!theVariable['backgroundColor']) // Browser without support will return undefined
theVariable['backgroundColor'] = 'rgb(0, 80, 0)';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.