html动态设置透明度

来源:互联网 发布:php网上商城教学日志 编辑:程序博客网 时间:2024/05/17 07:46

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>透明度调节</title>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.1/jquery.min.js"></script>
</head>
<style type="text/css">
.comcat{
width:300px;
height:15px;
background-color:#62A8D1;
display:block;
float:left;
margin:100px;}
table{
width:100%;
height:100%;}
td{
width:10px;
padding:0px;
margin:0px;
height:100%;
cursor:pointer;
}
.showdiv{
width:300px;
height:300px;
background:#9c58ab;
display:block;
float:left;
margin: 0px auto;
text-align:center;
}
.showdiv1{
width:100px;
height:100px;
background:#e87f23;
display:block;
margin-top:100px;
margin-left:100px;
text-align:center;
filter:alpha(opacity=60);
opacity:0.6;
    -moz-opacity:0.6;
    -khtml-opacity:0.6;
}
</style>
<body>
<div class="showdiv" >
<div class="showdiv1">

</div>
</div>
<div class="comcat">
<table>
<tr>
<td class="0"></td>
<td class="0.05"></td>
<td class="0.1"></td>
<td class="0.15"></td>
<td class="0.2"></td>
<td class="0.25"></td>
<td class="0.3"></td>
<td class="0.35"></td>
<td class="0.4"></td>
<td class="0.45"></td>
<td class="0.5"></td>
<td class="0.55"></td>
<td class="0.6"  style="background:#E87F23;"></td>
<td class="0.65"></td>
<td class="0.7"></td>
<td class="0.75"></td>
<td class="0.8"></td>
<td class="0.85"></td>
<td class="0.9"></td>
<td class="0.95"></td>
<td class="1"></td>
</tr>
</table>
</div>
<script type="text/javascript">
$(document).on('click', 'td', function() {
var that = this;
$(this).closest('table').find('td').each(function() {
$(this).css('background-color','');
});
$(this).css('background','#E87F23');
var number = $(this).attr("class");
$('.showdiv1').css("opacity", number);
});
</script>
</body>
</html>

0 0
原创粉丝点击