<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
ul,li{
list-style:none;
}
ul li{
margin-right:20px;
width:200px;
height:200px;
float:left;
background: brown;
opacity:0.3;
}
</style>
<script type="text/javascript">
window.onload = function () {
var aLi = document.getElementsByTagName("li");
for (var i = 0; i < aLi.length; i++) {
aLi[i].timer = null;
aLi[i].alpha = 0.3;
aLi[i].onmouseover = function(){
startMove(this,1);
}
aLi[i].onmouseout = function(){
startMove(this,0.3);
}
}
}
function startMove(obj,iTarget){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var speed = 0;
if(iTarget>obj.alpha){
speed = 0.1;
}
else {
speed = -0.1;
}
if(obj.alpha == iTarget){
clearInterval(obj.timer)
}
else{
obj.alpha += speed;
obj.style.opacity = obj.alpha ;
}
},10)
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>