Blogger Information
Blog 47
fans 0
comment 2
visits 102529
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
startMove运动框架
拾一枝樱花的博客
Original
1115 people have browsed it


实例

function getStyle(obj, attr, fn)
{
    if(obj.currentStyle)
    {
        return obj.currentStyle[attr];//ie
    }
    else
    {
        return getComputedStyle(obj, false)[attr];//ff
    }
}

function startMove(obj, json, fn)
{
    clearInterval(obj.timer);//开定时器之前先关掉原有的计时器
    obj.timer=setInterval(function (){
        var bStop=true; //这一次运动就结束了――所有的值都到达了
        for(var attr in json)
        {
//1.取当前的值
            var iCur=0;

            if(attr=='opacity')
            {
                iCur=parseInt(parseFloat(getStyle(obj, attr))*100);
            }
            else
            {
                iCur=parseInt(getStyle(obj, attr));
            }

//2.算速度
            var iSpeed=(json[attr]-iCur)/8;
            iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);

//3.检测停止
            if(iCur!=json[attr])
            {
                bStop=false;
            }

            if(attr=='opacity')
            {
                obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')';
                obj.style.opacity=(iCur+iSpeed)/100;
            }
            else
            {
                obj.style[attr]=iCur+iSpeed+'px';
            }
        }

        if(bStop)
        {
            clearInterval(obj.timer);

            if(fn)
            {
                fn();
            }
        }
    }, 30)
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

使用方式:

startMove('元素', 对象属性)

例:startMove('#id',{height: 100})

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post