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

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

簡單的動態伸縮為啥就是跑不起來呢?為什么瀏覽器工具會顯示obj.style.width錯誤

簡單的動態伸縮為啥就是跑不起來呢?為什么瀏覽器工具會顯示obj.style.width錯誤

lulubiu 2017-05-03 16:36:18
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title>多物體運動</title> <style> *{margin:?0;padding:?0} .li1{width:100px;height:100px;?margin-bottom:?50px;background-color:?teal;} .li2{width:100px;height:100px;?margin-bottom:?50px;background-color:?teal;} .li3{width:100px;height:100px;?margin-bottom:?50px;background-color:?teal;} </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=go(this,400); lis[i].onmouseout=go(this,100); } } function?go(obj,target) { clearInterval(obj.timer); obj.timer=setInterval(function(){ var?speed=(target-obj.offsetWidth)/30; speed=speed<0?Math.floor(speed):Math.ceil(speed); if(obj.offsetWidth==target){ clearInterval(obj.timer); } else{ obj.style.width=obj.offsetWidth+speed+'px'; } },30); } </script> </head> <body> <li></li> <li></li> <li></li> </body> </html>
查看完整描述

1 回答

?
風箏_0010

TA貢獻45條經驗 獲得超15個贊

因為onclick、onmouseover這種事件一般是賦值未運行的函數,比如lis[i].onmouseout=go; 而不是go()這種執行后的,所以你的go函數直接就在window環境里面執行了,傳入的this是指向window的。

查看完整回答
反對 回復 2017-05-03
  • 1 回答
  • 1 關注
  • 1319 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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