鼠標移出的時候,那塊div并不會 返回到最初的位置.
? ? window.onload = function () {
? ? ? ??
? ? ? ? var oDiv = document.getElementById('top');
? ? ? ? oDiv.onmouseover = function () {
? ? ? ? ? ? startMove(200);
? ? ? ? }
? ? ? ? oDiv.onmouseout = function () {
? ? ? ? ? ? startMove1(0);
? ? ? ? }
? ? }
? ? function startMove(end) {
? ? ? ? clearInterval(stop);
? ? ? ? var oDiv = document.getElementById('top');
? ? ? ? var stop = setInterval(function () {
? ? ? ? ? ? var speed = 0;
? ? ? ? ? ? if (oDiv.offsetLeft > end) {
? ? ? ? ? ? ? ? speed = -10;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? speed = 10;
? ? ? ? ? ? }
? ? ? ? ? ? if (oDiv.offsetLeft == end) {
? ? ? ? ? ? ? ? clearInterval(stop);
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? oDiv.style.left = oDiv.offsetLeft + speed + 'px';
? ? ? ? ? ? }
? ? ? ? }, 30);
? ? ? ??
? ? }
2015-10-26
注意第二個startMove。你寫錯了,寫成了startMove1()