我的多物體運動沒有反應(yīng)啊。
<!DOCTYPE html>
<html>
<head>
?? ?<meta charset="utf-8">
?? ?<title>多物體運動</title>
?? ?<style type="text/css">
?? ?ul,li{
?? ??? ?list-style: none;
?? ?}
?? ?ul li{
?? ??? ?width: 200px;
?? ??? ?height: 100px;
?? ??? ?background-color: yellow;
?? ??? ?margin-bottom: 20px;
?? ?}
?? ?</style>
?? ?<script type="text/javascript">
?? ??? ?var ali=document.getElementsByTagName('li');
?? ??? ?for(var i=0;i<ali.length;i++){
?? ??? ??? ?ali[i].onmouseover=function () {
?? ??? ??? ??? ?startMove(this,400);?? ?
?? ??? ??? ?}
?? ??? ??? ?ali[i].onmouseout=function () {
?? ??? ??? ??? ?startMove(this,200);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?var timer=null;
?? ??? ?function startMove(obj,iTarge){
?? ??? ??? ?clearInterval(timer);
?? ??? ??? ?timer=setInterval(function(){
?? ??? ??? ??? ?var speed=(iTarge-obj.offsetWidth)/8;
?? ??? ??? ??? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
?? ??? ??? ??? ?if(obj.offsetWidth==iTarge){
?? ??? ??? ??? ??? ?clearInterval(timer);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else{
?? ??? ??? ??? ??? ?obj.style.width=obj.offsetWidth+speed+'px';
?? ??? ??? ??? ?}
?? ??? ??? ?},30);
?? ??? ?}
?? ?</script>
</head>
<body>
<div>
?? ?<ul>
?? ??? ?<li></li>
?? ??? ?<li></li>
?? ??? ?<li></li>
?? ?</ul>
</div>
</body>
</html>
這是我的代碼。哪里寫錯了嘛。我的一點運動的痕跡都沒有。
2016-08-31
你的script中沒有觸發(fā)任何函數(shù),,,需要把你綁定的時間賦值給 window.onload