<div onmouseover="eval(str);" onmouseout="eval(str2);" id="ddd" style="border: 1px solid green; position: absolute; left: 100px; top: 10px; width: 100px; height: 30px; background: yellow;">
</div>
<script type="text/javascript">
<!--
var o = document.getElementById("ddd");
var str ='Move({\
obj: o,\
Begin: { top : o.offsetTop, left : o.offsetLeft, width : o.offsetWidth, height : o.offsetHeight},\
End: { top : o.offsetTop, left : o.offsetLeft, width : 300 ,height : 200}\
})';
var old = {width: o.offsetWidth, height: o.offsetHeight};
var str2 ='Move({\
obj: o,\
Begin: { top : o.offsetTop, left : o.offsetLeft, width : o.offsetWidth, height : o.offsetHeight},\
End: { top : o.offsetTop, left : o.offsetLeft, width : old.width ,height : old.height}\
})';
function Move(o) {
if(o.obj.t) clearTimeout(o.obj.t);
var goon = false;
var Time = o.Time || 10;
for (var i in o.End) {
var step = 0, neg = false;
var temp = o.End[i] - o.Begin[i];
if (temp == 0) continue;
if (temp < 0) {
neg = true;
temp = -temp;
}
step = temp < 4 ? 1 : temp >> 2;
if (step == 0){
o.obj.style[i] = o.End[i] + "px";
continue;
}
if (neg) step = -step;
o.obj.style[i] = (o.Begin[i] += step) + "px";
goon = true;
}
if (!goon) {
o.obj.t = null;
o.obj = null;
o = null;
return;
}
o.obj.t = setTimeout(function() {
Move(o);
}, Time)
}
//-->
</script>
回复 更多评论