亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

大家看看哪里出下問題了?

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>多物體動畫</title>

<style>

*{padding:0; margin:0; list-style: none;font-size: 36px;}

ul li{

/* width:150px; */

height:80px;

line-height: 80px;

background-color: #ff8040;

margin-bottom:20px;

border:4px #c0c0c0 solid;

text-align: center;

}

</style>

<script>

window.onload=function(){

var lis=document.getElementsByTagName("li");

for(var i=0;i<lis.length;i++)

{

lis[i].timer=null; ? ? ? ? ? ? ? ? ? ? //多物體運動所有參數不能共用,包括定時器,必須給各物體都加一個定時器

lis[i].onmouseover=function(){

move(this,300);

}

lis[i].onmouseout=function(){

move(this,150);

}

}

function move(obj,target){

clearInterval(obj.timer);

obj.timer=setInterval(function(){

var speed=(target-obj.offsetWidth)/10;

speed=speed>0?Math.ceil(speed):Math.floor(speed);

if(obj.offsetWidth==target)

clearInterval(obj.timer);

else

obj.style.width=parseInt(obj.style.width)+speed+'px';

},50);

}

}

</script>

</head>

<body>

<ul >

<li width="150px">1</li>

<li width="150px">2</li>

<li width="150px">3</li>

</ul>

</body>

</html>




正在回答

1 回答

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>多物體動畫</title>

<style>

*{padding:0; margin:0; list-style: none;font-size: 36px;}

ul li{

width:150px;

height:80px;

line-height: 80px;

background-color: #ff8040;

margin-bottom:20px;

border:4px #c0c0c0 solid;

text-align: center;

}

</style>

<script>

window.onload=function(){

var lis=document.getElementsByTagName("li");

for(var i=0;i<lis.length;i++)

{

lis[i].timer=null; ? ? ? ? ? ? ? ? ? ? //多物體運動所有參數不能共用,包括定時器,必須給各物體都加一個定時器

lis[i].onmouseover=function(){

move(this,300);

}

lis[i].onmouseout=function(){

move(this,150);

}

}

}

function getStyle(obj,attr){

if(obj.currentStyle){

return obj.currentStyle[attr];

}else{

return getComputedStyle(obj,false)[attr];

}

}

function move(obj,target){

clearTimeout(obj.timer);

obj.timer=setInterval(function(){

var atr=parseInt(getStyle(obj,'width'));

var speed=(target-atr)/10;

speed=speed>0?Math.ceil(speed):Math.floor(speed);

if(atr==target){

clearTimeout(obj.timer);

}

else{

obj.style.width=atr+speed+'px';

}

},50);

}

?

</script>

</head>

<body>

<ul >

<li width="150px">1</li>

<li width="150px">2</li>

<li width="150px">3</li>

</ul>

</body>

</html>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

大家看看哪里出下問題了?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號