问答详情
源自:4-1 JS多物体动画

求助:实在是不知道哪里错了,怎么调透明度都不变

<!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>


提问者:一颗猕猴桃 2016-06-07 15:41

个回答

  • 慕移动9181930
    2022-03-27 03:36:26

    把启用实时预览的对勾取消就行了

  • _9259
    2016-06-07 17:12:23

    我是新手。看你这段代码感觉乱乱的,是用改宽度的函数改的吧。

    把obj.style.opacity=obj.alpha/100;这段代码改成obj.style.opacity=iwidth/100;就好了