慕粉1847419605
2017-01-06 10:44
<!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>
*{padding:0;margin:0;}
#tmd{width:300px;height:300px;
background:green;
filter:alpha(opacity:30);
opacity:0.3;
}
</style>
<script>
window.onload=function(){
var odiv=document.getElementById('tmd');
odiv.onmouseover=function(){move(100);}
odiv.onmouseout=function(){move(30);}
}
var time=null,
TM=30;
function move(itarget){
var odiv=document.getElementById('tmd');
clearInterval(time);
time=setInterval(function(){
var speed=0;
if(TM<itarget){
speed=10;
}else{speed=-10;}
if(TM=itarget){clearInterval(time)}else{
TM=TM+speed;
odiv.style.filter='alpha(opacity:'+TM+')';
odiv.style.opacity= TM/100;
}
},30)
}
</script>
</head>
<div id="tmd"></div>
<body>
</body>
</html>
还没有人回答问题,可以看看其他问题
JS动画效果
113925 学习 · 1443 问题
相似问题