没有html / css没有内置的选项,但是因为你在
javascript中访问/设置颜色,你可以添加你自己的功能,它可以为你处理.
这是给你的一个例子:
function RGBA(red,green,blue,alpha) {
this.red = red;
this.green = green;
this.blue = blue;
this.alpha = alpha;
this.getCSS = function() {
return "rgba("+this.red+","+this.green+","+this.blue+","+this.alpha+")";
}
}
// store a copy of the color
var bgColor = new RGBA(255,0,0,0.5);
function setBgOpacity(elem, opac) {
bgColor.alpha = opac;
elem.style.backgroundColor = bgColor.getCSS();
}
然后在HTML中使用onmouseover事件来更改bgColor的不透明度:
onmousout="setBgOpacity(this, '0.5');">Put your mouse over me