var imgs = document.getElementsByClassName("i");
for (var i = 0; i < imgs.length; i++) {
imgs[i].onmouseover = function () {
startMov(this, { width: 150, height: 200, top: 0, left: 0 });
}
imgs[i].onmouseout = function () {
startMov(this, { width: 200, height: 450, top: -16, left: -150 });
}
//设置图像计时器为空值
imgs[i].timer = null;
}
function startMov(element, styles) {
clearInterval(element.timer);
element.timer = setInterval(function () {
for (var attr in styles) {
var icur = 0;
if (attr == 'width') {
icur = Math.round(parseFloat(getStyle(element, attr)) * 100);
} else{
icur = parseInt(getStyle(element, attr));
}
var speed = 0;
speed = (styles[attr] - icur) / 8;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (attr == 'width') {
element.style.width = (icur + speed) / 100;
} else {
element.style[attr] = icur + speed + 'px';
}
}
}, 30);
}
function getStyle(obj, attr) {
if (obj.currentStyle) {
return obj.currentStyle[attr]; //仅限IE兼容
} else {
return getComputedStyle(obj, false)[attr]; //兼容FF
}
}