superli18
2016-09-25 11:11
请问JS部分应该怎么改?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style type="text/css">
* {
margin:0;
padding:0;
}
ul li{
width:200px;
height:100px;
background:yellow;
list-style:none;
margin-top:20px;
filter:alpha(opacity:30);
opacity:0.3;
}
</style>
<script type="text/javascript">
window.onload=function(){
var lis=document.getElementsByTagName("li");
//var timer=null;
for(var i=0;i<lis.length;i++){
lis[i].alpha=30;
lis[i].timer=null;
lis[i].onmouseover=function(){
showMove(this,400,100);
}
lis[i].onmouseout=function(){
showMove(this,200,30);
}
}
function showMove(obj,target1,target2){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var sheed=(target1-obj.offsetWidth)/10;
if(sheed>0){
sheed=Math.ceil(sheed);
}else {
sheed=Math.floor(sheed);
}
var sheed2=0;
if(obj.alpha>target2){
sheed2=-5;
}else{
sheed2=5
}
if(obj.alpha == target2 && target1 == obj.offsetWidth){
clearInterval(obj.timer);
}else{
obj.alpha+=sheed2;
obj.style.filter="alpha(opacity:"+obj.alpha+")";
obj.style.opacity=obj.alpha/100;
obj.style.width=obj.offsetWidth+sheed+"px";
}
},30)
}
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
最后一句,obj.style.opacity=obj.alpha/10改为obj.style.opacity=obj.alpha/100,试试.我的代码与你的结构类似,两种效果都出来了
你的obj.alpha没有定义
没看懂你透明度是怎么个变化的!1
JS动画效果
113925 学习 · 1443 问题
相似问题