css背景透明度转换工具(兼容ie6)

 

<style type="text/css">
    #writeBox{background:#000;color:#fff;font-size:12px;line-height:20px;border:1px solid #ddd;padding:10px;}
</style>
color:<input type="text" id="color"> op:<input type="text" id="op" value="" /><input value="颜色转换" type="button" id="btn">
<div id="writeBox"></div>
<script type="text/javascript">
function $(id){
    return typeof id === "object" ? id : document.getElementById(id);
}
window.onload = function(){
    $("btn").onclick = function(){
        var c = new ColorChange();
        c.init();
    };
}
function ColorChange(){
    this.colorBox = $("color");
    this.tex = $("op");
    this.wBox = $("writeBox");
};
ColorChange.prototype = {
    color : function(){
        var c = this.colorBox,v = c.value;
        var op = this.tex.value;
        if (v=="") {
            return false;
        };
        var aa = v.substring(0,1);
        if(aa == "#"){
            v = v.substring(1,v.length);
        };
        var b=new Array(); 
         for(x=0;x<3;x++){ 
             b[0]=v.substr(x*2,2); 
             b[3]="0123456789abcdef"; 
             b[1]=b[0].substr(0,1); 
             b[2]=b[0].substr(1,1); 
             b[20+x]=b[3].indexOf(b[1])*16+b[3].indexOf(b[2]); 
         };
        var R = b[20],G = b[21],B = b[22];
        this.wBox.innerHTML += ":root div {<br>filter:none;/*处理ie9中的滤镜*/<br>background:rgba("+R+","+G+","+B+","+op+");<br>}<br>";
    },
    ap : function(){
        var a = this.tex.value;
        if(a==""){return false;}
        var num = Math.floor((Math.floor(a*100)/100)*255);
        var num_10 = (Math.floor(a*100)/100);
        var num_change = num.toString(16);
        if (num_change.length == 1){
            num_change = "0" + num_change;
        };
        var o = num_change.toUpperCase();
        o = o+this.colorBox.value;
        this.wBox.innerHTML += "div {<br>filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#"+o+"', endColorstr='#"+o+"');<br>}<br>";
    },
    init:function(){
        this.color();
        this.ap();
    }
};
</script>

转载于:https://www.cnblogs.com/starweb/archive/2012/10/22/2734369.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值