封装运动框架(轮播图)

以下全部为JS代码

function Animate(_ele){
    this.timer=null;
    this.hz=30;
    this.step=function(_css,_times){
        this.time=_times/this.hz;
        if(_css.left){
            this.hs=(Number(_css.left.match(/-*\d+/g)[0])-_ele.offsetLeft)/this.time;
            console.log(_css.left.match(/-*\d+/g)[0]);
        }
        if(_css.top){
            this.vs=(Number(_css.top.match(/-*\d+/g)[0])-_ele.offsetTop)/this.time;
        }
    }
    this.move=function(_css,_times,_fx){
        console.log("aa"+_css.left);
        var _me=this;
        var _conter=0;
        this.step(_css,_times);
        this.timer=setInterval(function(){
            if(_css.left){
                _ele.style.left=_ele.offsetLeft+_me.hs+"px";

            }
            if(_css.top){
                _ele.style.top=_ele.offsetTop+_me.vs+"px";
            }
            if(_conter++ >= _me.time){
                if(_css.left){
                    _ele.style.left=_css.left;
                }
                if(_css.top){
                    _ele.style.top=_css.top;
                }
                if(typeof _fx==="function"){
                    _fx();
                }
                clearInterval(_me.timer);
            }
        },_me.hz);
    }
    this.delay=function(_fx,_ms){
        var _me=this;
        this.timer=setTimeout(function(){
            clearTimeout(_me.timer);
            _fx();
        },_ms);
    }
    this.clear=function(){
        clearInterval(this.timer);
        // alert(1);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值