<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>多物體運動框架</title> <style> #div1 { width: 100px; height: 50px; background-color: red; margin-top:50px; } </style> <script type="text/javascript"> window.onload=function() { var oDiv = document.getElementById('div1'); oDiv.onmouseover=function() { startMove(300); } oDiv.onmouseout=function() { startMove(100); } } var timer = null; function startMove(iTarget)//這個函數(shù) { var oDiv = document.getElementById('div1'); clearInterval(timer); timer=setInterval(function () { var iSpeed = (iTarget - oDiv.offsetwidth)/8; iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); if(oDiv.offsetWidth == iTarget) { clearInterval(timer); } else { oDiv.style.width = oDiv.offsetWidth + iSpeed + 'px'; } },30) } </script></head><body> <div id="div1"></div></body></html>
這個變化函數(shù)哪里出問題了?
慕妹3146593
2019-04-19 15:15:48