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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自己的實驗中,給每個div設置了邊框,導致div回復不了初始位置,請問怎么解決有邊框的時候恢復初始位置?

自己的實驗中,給每個div設置了邊框,導致div回復不了初始位置,請問怎么解決有邊框的時候恢復初始位置?

wuzhoubo 2016-02-26 13:28:35
//百度之后知道offsetWidth包含了邊框厚度,請問怎么解決有邊框的時候恢復初始位置? <!DOCTYPE?html> <html> <head> ????<meta?charset="UTF-8"> ????<title>多物體運動</title> ????<style> ????????*?{ ????????????margin:?0; ????????????padding:?0; ????????} ????????ul?{ ????????????display:?block; ????????} ????????li?{ ????????????width:?200px; ????????????height:?100px; ????????????background-color:?#ccc; ????????????margin-top:?20px; ????????????border:?1px?solid; ????????} ????</style> ????<script> ????????window.onload?=?function?()?{ ????????????var?list?=?document.getElementsByTagName("li"); ????????????for?(var?i?=?0;?i?<?list.length;?i++)?{ ????????????????list[i].timer?=?null; ????????????????list[i].onmouseover?=?function?()?{ ????????????????????oMove(this,?400); ????????????????} ????????????????list[i].onmouseout?=?function?()?{ ????????????????????oMove(this,?200); ????????????????} ????????????} ????????????function?oMove(obj,?iTag)?{ ????????????????clearInterval(obj.timer); ????????????????obj.timer?=?setInterval(function?()?{ ????????????????????var?speed?=?(iTag?-?obj.offsetWidth)?/?8; ????????????????????speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed); ????????????????????if?(obj.offsetWidth?==?iTag)?{ ????????????????????????console.log(obj.offsetWidth); ????????????????????????clearInterval(obj.timer); ????????????????????}?else?{ ????????????????????????obj.style.width?=?obj.offsetWidth?+?speed?+?'px'; ????????????????????} ????????????????},?30); ????????????} ????????} ????</script> </head> <body> <ul> ????<li></li> ????<li></li> ????<li></li> </ul> </body> </html>
查看完整描述

2 回答

已采納
?
Halo_

TA貢獻23條經驗 獲得超10個贊

box-sizing:border-box;

查看完整回答
1 反對 回復 2016-02-26
?
慕郎_蓮華

TA貢獻83條經驗 獲得超16個贊

記得選擇代碼語言哦http://img1.sycdn.imooc.com//56d033580001492d01760300.jpg


你設置寬度的時候 減去邊框的寬度就好了

查看完整回答
反對 回復 2016-02-26
  • 2 回答
  • 0 關注
  • 1674 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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