firefox与IE透明度(opacity)设置区别

IE:
filter:alpha(opacity=sqlN)
其中 sqlN的值域为[0, 100]

js: ieNode.style.filter="alpha(opacity=sqlN)";  

Firefox,Chrome和Safari:
opacity:sqlN
其中sqlN的值域为[0, 1]

js: firefoxNode.style.opacity=sqlN;  

 

测试代码如下:

<HTML>
<HEAD>
    <style type="text/css">
        .ieCss {
            display:-moz-inline-box;
            display:inline-block;
            width:100;
            height:100;
            background-color:red;
            filter:alpha(opacity=20);
        }
        .fireFoxCss {
            display:-moz-inline-box;
            display:inline-block;
            width:100;
            height:100;
            background-color:blue;
            opacity:0.5;
        }
    </style>

    <script>
        window.onload = function() {
            //设置IE
            var ieSpanJs = document.getElementById("ieSpanJs");
            ieSpanJs.style.display = "inline-block";  //ie支持
            ieSpanJs.style.width = 100;
            ieSpanJs.style.height = 100;
            ieSpanJs.style.backgroundColor = "red";
            ieSpanJs.style.filter="alpha(opacity=20)";

            //设置firefox
            var firefoxSpanJs = document.getElementById("firefoxSpanJs");
            try
            {
                firefoxSpanJs.style.display = "-moz-inline-box"; //firefox支持
            }
            catch (e)
            {
                firefoxSpanJs.style.display = "inline-block"; //支持IE
            }

            firefoxSpanJs.style.width = 100;
            firefoxSpanJs.style.height = 100;
            firefoxSpanJs.style.backgroundColor = "blue";
            firefoxSpanJs.style.opacity="0.5";

        }
    </script>

</HEAD>

<BODY>
<span id="ieSpanCss" class="ieCss">IE_css</span>
<span id="firefoxSpanCss" class="fireFoxCss">firefox_css</span>
<br>
<br>
<span id="ieSpanJs">IE_Js</span>
<span id="firefoxSpanJs">firefox_Js</span>
</BODY>
</HTML>

 

补充:参考资料中对firfox还有3.5之前和3.5之后版本的区分,暂时忽略。

 

参考文档:

http://hi.baidu.com/hanserv/item/ac31a23f0c578bffdf222114

转载于:https://www.cnblogs.com/jsxiangxiang/archive/2013/04/30/3051538.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值