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

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

為什么我的offsetLeft每次加9px

<!doctype>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

<title>透明度動畫</title>

<style type="text/css">

#wrap{width:230px;height:105px;position: relative;left:-217px;}

#red{width:200px;height:100px;background-color: red;position: absolute;}

#blue{width:30px;height:30px;background-color: blue;margin-left: 200px;position: absolute;}

</style>

<script type="text/javascript">

window.onload=function(){

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

var timer=null

wrap.onmouseover=function(){

startMove();

}

}


function startMove(){

timer=setInterval(function(){?


if(wrap.offsetLeft==0){

clearInterval(timer);

}

else{


wrap.style.left=wrap.offsetLeft+1+'px'; //console.log(wrap.offsetLeft);

}

},300);

}

</script>

</head>

<body>

<div id="wrap">

<div id="red"></div>

<div id="blue"></div> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

</div>

</body>

</html>

為什么我的offsetLeft每次加9px

正在回答

1 回答

因為wrap獲取的offsetLeft不是217 ?而是209

他把body的margin也算進去了

修改辦法:

在樣式里添加: ?*{ padding:0; margin:0}

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

舉報

0/150
提交
取消

為什么我的offsetLeft每次加9px

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

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

幫助反饋 APP下載

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

公眾號

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