<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div{
width: 200px;
height: 200px;
background: red;
filter: alpha(opacity:30);
opacity: 0.3;
margin: 10px;
float: left;
}
</style>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
var odiv=document.getElementsByTagName('div');
for(var i=0;i<odiv.length;i++){
odiv[i].alpha=30;
odiv[i].timer=null;
odiv[i].onmouseover=function(){
startMove(this,100);
}
odiv[i].onmouseout=function(){
startMove(this,30);
}
}
}
function startMove(obj,iTarget){
clearInterval(obj.timer);
if(alpha>iTarget){
speed=-10;
}else{
speed=10;
}
obj.timer=setInterval(function(){
if(alpha==iTarget){
clearInterval(obj.timer);
}else{
alpha+=speed;
obj[i].style.filter='alpha(opacity:'+alpha+')';
obj[i].style.opacity=alpha/100;
}
},30)
}
</script>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>
不断滴自我催眠