一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

js仿新浪微博消息发布功能

时间:2017-04-14 编辑:简简单单 来源:一聚教程网

 代码如下 复制代码

仿新浪微博消息发布功能

  

  

    

    

    

chuan,js为之前写的完美运动框架:

 代码如下 复制代码

functiongetstyle(obj,name)

  {

if(obj.currentStyle)

{

returnobj.currentStyle;

}

else

{

returngetComputedStyle(obj,false)[name];

}

  }

      functionmove(obj,json,fnEnd)

{

clearInterval(obj.timer);

obj.timer=setInterval(function()

{

 varbBox=true;//假设所有值都已经到了

 for(varstrrinjson)

 {

 if(strr=='opacity')

 {

  varcur=Math.round(parseFloat(getstyle(obj,strr))*100);

 }

 else

 {

  varcur=parseInt(getstyle(obj,strr));

 }

 varspeed=(json[strr]-cur)/10;

 speed=speed>0?Math.ceil(speed):Math.floor(speed);

  

 if(cur!=json[strr])

 bBox=false;

 if(strr=='opacity')

            {

            obj.style.filter='alpha(opacity:'+(cur+speed+')');

            obj.style.opacity=(cur+speed)/100;

            }

 else

 {

 obj.style[strr]=cur+speed+'px';

 }

 }

 if(bBox)

 {

 clearInterval(obj.timer);

 if(fnEnd)fnEnd();

 }

},30);

};

热门栏目