-
Notifications
You must be signed in to change notification settings - Fork 26
/
rgba的ie浏览器支持换算器.htm
executable file
·112 lines (101 loc) · 5.74 KB
/
rgba的ie浏览器支持换算器.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS背景颜色属性值转换_实现背景色透明效果的代码_小志博客_wwww.linxz.de_css那些事儿</title>
<meta name="keywords" content="css那些事儿,林小志,linxz,林友赛,linxz.de,透明背景色,渐变,滤镜" />
<meta name="description" content="实现各个浏览器中具备良好的透明特性的效果,IE中使用私有滤镜filter,高端浏览器使用CSS3中的rgba属性。林小志的个人博客站点,《CSS那些事儿》书籍的作者,专注于页面重构的思维,关注于页面制作中结构的扩展性以及可维护性。" />
<style type="text/css">
label {color:#F32600;}
label,button {cursor:pointer;}
input {width:100px;height:18px;text-align:center;font-family:Tahoma;font-size:12px;color:#F32600;}
textarea {width:600px;height:40px;margin-top:20px;line-height:20px;padding:5px;font-size:13px;font-family:Tahoma;color:#A6CAF0;border:1px solid #FFFFFF;background-color:#272727;}
#simple {width:200px;height:100px;overflow:hidden;text-align:center;line-height:100px;}
.wrap {width:650px;overflow:hidden;margin:20px auto 0;zoom:1;}
</style>
</head>
<body>
<h1><a href="http://blog.linxz.de/ie_filter_css3_rgba/" title="CSS背景颜色属性值转换">CSS背景颜色属性值转换</a></h1>
<h2>实现背景色透明效果的代码</h2>
<p>实现各个浏览器中具备良好的透明特性的效果,IE中使用私有滤镜filter,高端浏览器使用CSS3中的rgba属性。</p>
<p>输入十六进制的颜色值以及透明度,自动在IE的过渡滤镜以及CSS3中的rgba属性之间进行十六进制与十进制的换算。</p>
<hr />
<div class="wrap">
<label for="color_value">需要透明的颜色十六进制值:#</label><input type="text" value="" id="color_value" maxlength="6" />
<label for="original">透明度:</label><input type="input" id="original" />
<button type="button" onclick="change_10_to_16()">转为16进制的颜色</button>
<br />
<textarea rows="2" cols="90" id="alpha_style"></textarea>
</div>
<script type="text/javascript">
var oOriginal = document.getElementById("original");
var co_value = document.getElementById("color_value");
var css_cont = document.getElementById("alpha_style");
function change_10_to_16() {
var pattern = /^[0-9a-fA-F]{6}$/;
var pattern_3 = /^[0-9a-fA-F]{3}$/;
var co = co_value.value;
var num = Math.floor((Math.floor(oOriginal.value*100)/100)*255);
var num_10 = (Math.floor(oOriginal.value*100)/100);
var num_change = num.toString(16);
num = parseInt(num);
if (co.match(pattern) == null){
if (co.length == 3){
if (co.match(pattern_3) == null){
alert("十六进制是从【0】到【9】以及【a】到【f】组合而成的,再来一次吧!\n如果是十六进制的缩写,是前后相邻的字母可简写成为一个,例如【#FF000FF】可转为【#F0F】\n请检查你的颜色值是否为【三位】或者符合【十六进制的组合方式】。");
}else{
if (oOriginal.value >=0 && oOriginal.value <= 1){
if (num_change.length == 1){
num_change = "0" + num_change;
}
var co_a = co.substring(0, 1);
var co_b = co.substring(1, 2);
var co_c = co.substring(2, 3);
var co_a2 = co_a + co_a;
var co_b2 = co_b + co_b;
var co_c2 = co_c + co_c;
co = co_a2 + co_b2 + co_c2;
css_cont.innerHTML = "filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#" + num_change.toUpperCase() + co.toUpperCase() + "', endColorstr='#" + num_change.toUpperCase() + co.toUpperCase() + "');background:rgba(" + parseInt(co_a2,16) + "," + parseInt(co_b2,16) + "," + parseInt(co_c2,16) + "," + num_10 + ");";
}else{
alert("透明度的值在【0】到【1】之间。");
}
}
}else{
alert("十六进制是从【0】到【9】以及【a】到【f】组合而成的,再来一次吧!\n如果是十六进制的缩写,是前后相邻的字母可简写成为一个,例如【#FF000FF】可转为【#F0F】\n请检查你的颜色值是否为【三位】或者符合【十六进制的组合方式】。");
}
}else{
if (oOriginal.value >=0 && oOriginal.value <= 1){
if (num_change.length == 1){
num_change = "0" + String(num_change);
}
var co_a = co.substring(0, 2);
var co_b = co.substring(2, 4);
var co_c = co.substring(4, 6);
css_cont.innerHTML = "filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#" + num_change.toUpperCase() + co.toUpperCase() + "', endColorstr='#" + num_change.toUpperCase() + co.toUpperCase() + "');background:rgba(" + parseInt(co_a,16) + "," + parseInt(co_b,16) + "," + parseInt(co_c,16) + "," + num_10 + ");";
}else{
alert("透明度的值在【0】到【1】之间。");
}
}
}
</script>
<div style="position:absolute;bottom:0;right:0;font-size:12px;">
<script language="javascript" type="text/javascript" src="http://js.users.51.la/385492.js"></script>
<noscript>
<a href="http://www.51.la/?385492" target="_blank">
<img alt="我要啦免费统计" src="http://img.users.51.la/385492.asp" style="border:none" />
</a>
</noscript>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-494463-3']);
_gaq.push(['_setDomainName', '.linxz.de']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>