一颗猕猴桃
2016-06-07 15:41
<!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>
*{margin:0;padding:0;}
ul,li{list-style: none;
}
ul li{
width:200px;
height:200px;
background:#666;
margin: 10px;
float: left;
opacity: 0.3;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oLi=document.getElementsByTagName("li");
for (var i = 0;i<oLi.length;i++){
oLi[i].alpha=30;
oLi[i].onmouseover=function(){
startMove(this,100);
}
oLi[i].onmouseout=function(){
startMove(this,30);
}
}
}
function startMove(obj,iwidth){
//var oLi=document.getElementsByTagName("li");
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=0;
if (obj.alpha>iwidth) {
speed=-10;
}else{
speed=10;
};
if (obj.alpha==iwidth) {
clearInterval(obj.timer);
}else{
obj.alpha=obj.alpha+speed+"px";
obj.style.opacity=obj.alpha/100;
}
},30)
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
我是新手。看你这段代码感觉乱乱的,是用改宽度的函数改的吧。
把obj.style.opacity=obj.alpha/100;这段代码改成obj.style.opacity=iwidth/100;就好了
JS动画效果
113925 学习 · 1443 问题
相似问题