2012年11月9日 星期五

CSS:opacity 的相容性


以這段程式碼為例:

function gradient(id, level)
{
    var box = document.getElementById(id);
    box.style.opacity = level;
    box.style.MozOpacity = level;
    box.style.KhtmlOpacity = level;
    box.style.filter = "alpha(opacity=" + level * 100 + ")";
    box.style.display="block";
    return;
}

box.style.opacity = level; //相容於 Firefox、Safari、Opera、IE8 and previous
box.style.MozOpacity = level; //Firefox 0.9
box.style.KhtmlOpacity = level; //Safari 1.2
box.style.filter = "alpha(opacity=" + level * 100 + ")"; //IE9.0 and above

Reference:
https://developer.mozilla.org/en-US/docs/CSS/opacity

沒有留言:

張貼留言