如何在JavaScript中获取不透明度当前值?

时间:2013-09-23 23:13:19

标签: javascript css internet-explorer-10

我已经看到了一些话题,但没有一个具有IE10特定的解决方案。我知道IE10遵循W3C,但我无法找到“官方w3c解决方案”来获取DOM元素的当前不透明度值。下面是我到目前为止的代码(这里有一个pice,另一个来自那里......):

jGp.nau.padrao是根据浏览器的先前设置。将是“ie”或“w3c”。只要IE10在这种情况下可能是“w3c”,它仍然是我在这个库中的其他功能的有用选项。 Target是一个DOM元素。

jGp.ee.getAlpha = function(target){
    if(jGp.nau.padrao=='w3c'){
        var temp_style = document.defaultView.getComputedStyle(target,null); 
        if (!isNaN(temp_style.opacity)) { 
            opacityVal = temp_style.opacity; 
        } else if (!isNaN(temp_style.MozOpacity)) { 
            opacityVal = temp_style.MozOpacity; 
        } else {
            opacityVal = 1; // default value so my code will not crash
        }
        return parseFloat(opacityVal*100);
    } else {
        try {
            return target.filters.item('DXImageTransform.Microsoft.Alpha').Opacity;
        } catch(e) {
            return 100; // default value so my code will not crash
        }
    } 
}

我可以包含IE版本,以前也检测过,我只需要为此定义正确的代码。到目前为止,此代码适用于FireFox,Chrome和Safari(我猜Opera也是如此)。

0 个答案:

没有答案