Shelagh4233277
2016-11-22 00:14
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style type="text/css">
*{
padding:0px;
margin:0px;
}
#sqr{
width:200px;
height:200px;
background:red;
filter:alpha(opacity:30);
opacity:0.3;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>透明度</title>
<script>
window.onload=function(){
var dd=document.getElementById("sqr");
dd.onmouseover=function(){
startmove();
}
var a=null;
var alpha=30;
function startmove(){
var dd=document.getElementById("sqr");
clearInterval(a);
a=setInterval(function(){
if(alpha==100)
{ clearInterval(a);}
else{
alpha=alpha+10;
dd.style.filter="alpha(opacity:"+alpha+")";
dd.style.opacity=alpha/100;
}
},30)
}
</script>
</head>
<body>
<div id="sqr">
</div>
</body>
</html>
JS代码最后少了一个"}",补上就行了
JS动画效果
113925 学习 · 1443 问题
相似问题