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

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

*{margin:0;padding:0;} 為什么不寫這個,就停不下來了?

<!DOCTYPE html>

<html>

<head>

<title>動畫</title>

<style type="text/css">

#box{

width: 200px;

height: 100px;

background-color: black;

position: relative;

left:-200px;

}

#share{

width: 30px;

height: 50px;

background-color: blue;

position: absolute;

left:200px;

}

</style>

</head>

<body>

<div id="box"><span id="share"></span></div>

<script type="text/javascript">

window.onload=function(){

var odiv=document.getElementById('box');

odiv.onmouseover=function(){

startMove();

}

var timer=null;

function startMove(){

timer=setInterval(function(){

if(odiv.offsetLeft==0){

clearInterval(timer);

}

else{

odiv.style.left=odiv.offsetLeft+10+'px';

}

},30)

}

}

</script>

</body>

</html>


正在回答

1 回答

跟css中的{margin:0;padding:0;} 沒有關(guān)系,你的代碼中,判斷offsetLeft 的條件改為: if(odiv.offsetLeft>=0) ?它就停下來了 ,因為在不斷移動的過程中,不一定有0這個值

還有一個問題,進入startMove()時, 需要先清除一下定時器,目的是保證同時只有一個定時器在運行,你的代碼還給你,就改了兩個地方:

<!DOCTYPE html>

<html>

<head>

<title>動畫</title>

<style type="text/css">

#box{

width: 200px;

height: 100px;

background-color: black;

position: relative;

left:-200px;

}

#share{

width: 30px;

height: 50px;

background-color: blue;

position: absolute;

left:200px;

}

</style>

</head>

<body>

<div id="box"><span id="share"></span></div>

<script type="text/javascript">

window.onload = function() {

? ? var odiv = document.getElementById('box');

? ? odiv.onmouseover = function() {

? ? ? ? startMove();

? ? }

? ? var timer = null;

? ? function startMove() {

? ? ? ? clearInterval(timer); ? ? ? ? ? ? ? ?// debug ?1

? ? ? ? timer = setInterval(function() {

? ? ? ? ? ? console.log(odiv.offsetLeft)

? ? ? ? ? ? if (odiv.offsetLeft >= 0) { ? ? ?// ?debug 2

? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? odiv.style.left = odiv.offsetLeft + 10 + 'px';

? ? ? ? ? ? }

? ? ? ? },

? ? ? ? 300)

? ? }

}

</script>

</body>

</html>



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

舉報

0/150
提交
取消

*{margin:0;padding:0;} 為什么不寫這個,就停不下來了?

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

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

幫助反饋 APP下載

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

公眾號

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