Sinoproud
2016-04-26 20: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=utf-8" />
<title>透明动画</title>
<style type="text/css">
*{margin:0; padding:0;}
#div1{width:200px; height:200px; background:red; opacity:0.3;}
</style>
<script type="text/javascript">
window.onload=function(){
var div1=document.getElementById('div1');
div1.onmouseover=function(){startMove(1.0)};
div1.onmouseout=function(){startMove(0.3)};
}
var timer=null;
var alpha=0.3;
function startMove(iTarget){
var div1=document.getElementById('div1');
clearInterval(timer)
var speed=0;
if(alpha>iTarget){
speed=-0.1;
}
else{speed=0.1;}
timer=setInterval(function(){
if(alpha==iTarget){
clearInterval(timer);
}
else{
alpha=alpha+speed;
div1.style.opacity=alpha;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
后面分号掉了吧,加上分号试试
JS动画效果
113925 学习 · 1443 问题
相似问题
回答 2
回答 1