第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

垂直居中有沒(méi)有更好的方法(怎么用table-cell,用了有一系列問(wèn)題。。)。為什么t要先置空,賦setInterval給t時(shí),前面用var t就不動(dòng)了。

<style type="text/css">

*{margin:0;padding:0;}

#box1{width:200px;height:300px;background:#CCF; position:relative;left:-200px;top:100px;border-bottom-right-radius:10px; border-top-right-radius:10px;}

#box2{width:40px;height:100px;background:#F00;text-align:center;border-bottom-right-radius:10px; border-top-right-radius:10px; color:#FFF; font-weight:900; position:absolute;left:200px;top:100px;}

#a{padding-top:32px;}

</style>


</head>


<body>

<div id="box1">

<div id="box2">

<div id="a"><p>分</p>

<p>享</p></div>

</div>

</div>

<script type="text/javascript">

var box2=document.getElementById("box2");

var box1=document.getElementById("box1");

var t=null;

box1.onmouseover=move;

function move(){

clearInterval(t);

t=setInterval(function(){

if(box1.offsetLeft==0){clearInterval(t);}

else { speed=(0-box1.offsetLeft)/20;

box1.style.left=box1.offsetLeft+Math.ceil(speed)+"px";}

},30);

}

box1.onmouseout=move1;

function move1(){

clearInterval(t);

t=setInterval(function(){

if(box1.offsetLeft==-200){clearInterval(t);}

else { speed=(-200-box1.offsetLeft)/20;

box1.style.left=box1.offsetLeft+Math.floor(speed)+"px";}

},30);

}

</script>

</body>


正在回答

1 回答

得用js取到屏幕的clientHeight,然后取到元素的offsetHeight,位置為top=(clientWidth-offsetHeight)/2 表示居中位置,t表示全局變量,就一個(gè)定時(shí)器在工作吧

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
JS動(dòng)畫效果
  • 參與學(xué)習(xí)       113920    人
  • 解答問(wèn)題       1487    個(gè)

通過(guò)本課程JS動(dòng)畫的學(xué)習(xí),從簡(jiǎn)單動(dòng)畫開(kāi)始,逐步深入各種動(dòng)畫框架封裝

進(jìn)入課程

垂直居中有沒(méi)有更好的方法(怎么用table-cell,用了有一系列問(wèn)題。。)。為什么t要先置空,賦setInterval給t時(shí),前面用var t就不動(dòng)了。

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)