TestMove.js
View Code
function getStyle(obj, attr) { if (obj.currentStyle) { return obj.currentStyle[attr]; } else { return getComputedStyle(obj, false)[attr]; }}function startMove(obj, json, fn) { clearInterval(obj.timer); obj.timer = setInterval(function () { var bStop = true; //停止运动的标记 for (var attr in json) { var iCurr = 0; //获取当前的值 if (attr == 'opacity') { iCurr = parseInt(Math.round(parseFloat(getStyle(obj, attr)) * 100)); } else { iCurr = parseInt(getStyle(obj, attr)); } //计算速度 var iSpeed = (json[attr] - iCurr) / 8; iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); //检测是否停止 if (iCurr != json[attr]) { bStop = false; } //设置属性 if (attr == 'opacity') { obj.style.filter = 'alpha(opacity:' + iCurr + iSpeed + ')'; obj.style.opacity = (iCurr + iSpeed) / 100; } else { obj.style[attr] = iCurr + iSpeed + 'px'; } } if (bStop) { clearInterval(obj.timer); if (fn) { fn(); } } }, 30);}
TestMove.html
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication5.WebForm3" %> 2 3 4 5 6 731 328 18 19 24 25 26