创建运动函数startMove(obj,attr,iTarget)

来源:互联网 发布:如何评价太祖知乎 编辑:程序博客网 时间:2024/06/03 19:00
//获取对象的属性
function getStyle(obj, name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputedStyle(obj, false)[name];
}
}
//运动函数的构造(对象,属性,目标)
function startMove(obj, attr, iTarget)
{
//清除时间间隔
clearInterval(obj.timer);

//清除时间间隔
obj.timer=setInterval(function (){
var cur=0;
//透明度的设置
if(attr=='opacity')
{
cur=Math.round(parseFloat(getStyle(obj, attr))*100);
}
//除了透明度以外的属性设置
else
{
cur=parseInt(getStyle(obj, attr));
}
//速度的设置
var speed=(iTarget-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur==iTarget)
{
clearInterval(obj.timer);
}
else
{
if(attr=='opacity')
{
obj.style.filter='alpha(opacity:'+(cur+speed)+')';
obj.style.opacity=(cur+speed)/100;
document.getElementByIdx_x_x_x('txt1').value=obj.style.opacity;
}
else
{
obj.style[attr]=cur+speed+'px';
}
}
}, 30);
}

调用的方法如下:
oBtnPrev.onmouseover=oMarkLeft.onmouseover=function ()
{
startMove(oBtnPrev, 'opacity', 100);
};
原创粉丝点击