日期:2014-05-16 浏览次数:20379 次
<script>
function getByClass(oParent,sClass)
{
var aEle=oParent.getElementsByTagName("*");
var aResult=[];
var re=new RegExp("\\b"+sClass+"\\b");
for(var i=0;i<aEle.length;i++)
{
if(re.test(aEle[i].className))
{
aResult.push(aEle[i]);
}
}
return aResult;
}
function getStyle(obj,name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
//对火狐下取backgroundPositioY的值特别处理一下
if(name=="backgroundPositionX")
{
if(window.navigator.userAgent.indexOf("Firefox")!=-1)//火狐
{
return parseInt(getComputedStyle(obj,false).backgroundPosition);
}
else
{
return getComputedStyle(obj,false)[name];
}
}
else if(name=="backgroundPositionY")
{
if(window.navigator.userAgent.indexOf("Firefox")!=-1)//火狐
{
return getComputedStyle(obj,false).backgroundPosition.split(" ")[1];
}
else
{
return getComputedStyle(obj,false)[name];
}
}
else
{
return getComputedStyle(obj,false)[name];
}
}
}
function startMove(obj,json,interval,type,fnEnd)
{
var stressSpeed=0;
var pattern={};
for(var attr in json)
{
pattern[attr]=parseInt(getStyle(obj,attr));
}
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var bEnd=true;
for(var attr in json)
{
switch(type)
{
case "stress":
stressSpeed+=(json[attr]-pattern[attr])/10;
stressSpeed*=0.75;
pattern[attr]+=stressSpeed;
obj.style[attr]=pattern[attr]+"px";
if(Math.abs(pattern[attr]-json[attr])>0.1&&Math.abs(stressSpeed)>0.1)
{
bEnd=false;
}
break;
case "buffer":
var cur=0;
if(attr=="opacity")
{
cur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else
{
cur=parseInt(getStyle(obj,attr));
}
var bufferSpeed=(json[attr]-cur)/8;
bufferSpeed=bufferSpeed>0?Math.ceil(bufferSpeed):Math.floor(bufferSpeed);
if(attr=="opacity")
{
obj.style.opacity=(cur+bufferSpeed)/100;
obj.style.filter="alpha:(opacity="+(cur+bufferSpeed)+")";
}
else
{
if((attr=="backgroundPositionX"||attr=="backgroundPositionY")&&window.navigator.userAgent.indexOf("Firefox")!=-1)
{
if(attr=="backgroundPositionX")
{
var y=getStyle(obj,"backgroundPositionY");
obj.style.backgroundPosition=cur+bufferSpeed+" "+y+"px";
}
else
{
var x=getStyle(obj,"backgroundPositionX");
obj.style.backgroundPosition=x+"px "+(cur+bufferSpeed)+"px";
}
}
else
{
obj.style[attr]=cur+bufferSpeed+"px";
}
}
if(cur!=json[attr])
{
bEnd=false;
}
break;
}
}
if(bEnd)
{
clearInterval(obj.timer);
for(var attr in jso