為什么我的毫無反應呢??半天都沒找出來。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JS多物體運動動畫</title>
<style type="text/css">
ul,li{
list-style:none;}
ul li{
width:200px;
height:100px;
background:yellow;
margin-bottom:20px;}
</style>
<script type="text/avascript">
?window.onload=function(){
var aLi=document.getElementsByTagName("li");//aLi為數(shù)組
for(var i=0;i<aLi.length;i++)
{
aLi.time=null;
aLi[i].onmouseover=function(){
startMove(this,400);
}
aLi[i].onmouseout=function(){
startMove(this,200);
}
}
?}
? ? aLi[i].timer=null;
function startMove(obj,terget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(terget-obj.offsetWidth)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==terget){clearInterval(obj.timer);}?
else{obj.style.width=obj.offsetWidth+speed+"px";
},30)
?
}
</script>
</head>
<body>
?<ul>
? ?<li></li>
? ?<li></li>
? ?<li></li>
?</ul>
</body>
</html>
2016-03-21
你好,其實只是一些小問題,
<script type="text/avascript">是javascript,這個應該影響不大,
aLi.time=null;aLi[i].timer=null;//應該是點的哪一個
function startMove(obj,terget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(terget-obj.offsetWidth)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==terget){clearInterval(obj.timer);}?
else{obj.style.width=obj.offsetWidth+speed+"px";
},30)? //掉了一個'}',這是主要的
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JS多物體運動動畫</title>
<style type="text/css">
ul,li{
list-style:none;}
ul li{
width:200px;
height:100px;
background:yellow;
margin-bottom:20px;}
</style>
<script type="text/javascript">
?window.onload=function(){
var aLi=document.getElementsByTagName("li");//aLi為數(shù)組
for(var i=0;i<aLi.length;i++){
aLi[i].timer=null;
aLi[i].onmouseover=function(){
startMove(this,400);
}
aLi[i].onmouseout=function(){
startMove(this,200);
}
}
?}
function startMove(obj,terget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(terget-obj.offsetWidth)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==terget){clearInterval(obj.timer);}
else{obj.style.width=obj.offsetWidth+speed+"px";
}
},30)
?
}
</script>
</head>
<body>
?<ul>
?? <li></li>
?? <li></li>
?? <li></li>
?</ul>
</body>
</html>
?