运行代码 缩小
汉王
HTML代码
复制 格式化 注释 注释 清空
放大
AخA
 
1
<!DOCTYPE html>  
2
<html>  
3
<head>  
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
5
<title>JS封装透明度</title>  
6
</head>  
7
<style>  
8
#test1{width:250px;height:250px;text-align:center;background-color:#930;margin:0 auto;color:#F00;}  
9
#test2{width:250px;height:250px;text-align:center;background-color:blue;margin:0 auto;color:#f00;}  
10
</style>  
11
<body bgcolor="#eee">  
12
    <div id="test1">我是模块1</div>  
13
    <div id="test2">我是模块2</div>  
14
    <script>  
15
        /* 封装setOpacity函数 
16
         * node 类名 level 透明度 */  
17
            function setOpacity(node,level){  
18
                node = typeof node=="string" ? document.getElementById(node) : node;  
19
                if(document.all){ //document.all 是IE支持属性 firefox 不支持  
20
                    node.style.filter = 'alpha(opacity=' + level+ ')';  
21
                }else{  
22
                    node.style.opacity= level/100;    
23
                }         
24
            }   
25
        /*  调用函数 */  
26
        setOpacity("test1",20);  
27
        setOpacity("test2",20);  
28
    </script>  
29
</body>  
30
</html>  
CSS代码
复制 格式化 注释 注释 颜色 清空
放大
CSS代码...
x
 
1
JS代码
复制 格式化 注释 注释 清空
放大
JS代码...
xxxxxxxxxx
1
 
1
名称
JS封装和调用函数(透明度函数封装)
分类
网站常用
描述
JS封装和调用函数(透明度函数封装),学习封装一个透明函数,经典的高人帖子,分享给前端设计新手们围观,抛砖!
收藏