我们先来看下之前的运动的代码,是否支持多物体运动,会出现怎么样的问题。
代码如下:
<style type="text/css">
div {
width: 100px;
height: 50px;
background: red;
margin: 10px;
}
</style>
代码如下:
<body>
<div></div>
<div></div>
<div></div>
</body>
以下是Javascript 代码:
代码如下:
<script type="text/javascript">
window.onload = function() {
var aDiv = document.getElementsByTagName('div');
for (var i = 0; i < aDiv.length; i++) {
aDiv[i].onmouseover = function() {
startMove(this, 400);
};
aDiv[i].onmouseout = function() {
startMove(this, 100);
};
}
}
var timer = null;
function startMove(obj, iTarget) {
clearInterval(timer);
timer = setInterval(function() {
新闻热点
疑难解答
图片精选