js拳皇特效

js拳皇特效

效果图
这里写图片描述


很简单的特效,运用了面向对象,原型等简单的方法。
废话不多说,上代码:

<script>
    /*
     * 前进 39
     * 后退 37
     * 集气 o 79
     * */
    function Yagami(player) {
        //类 构造函数
        this.player=player;
        this.left=0;
        this.time=null;
    }
    var skilllist = {
        39: function () {
            //前进
            this.player.src="quanhuang/advance.gif";
            this.time=setInterval(function () {
                this.left+=3;
                if(this.left>=500){
                    this.left=500;
                }
                this.player.style.left=this.left+"px";
            }.bind(this),13)
        },
        37: function () {
            //后退
            this.player.src="quanhuang/retreat.gif";
            this.time=setInterval(function () {
                this.left-=3;
                if(this.left<=0){
                    this.left=0;
                }
                this.player.style.left=this.left+"px";
            }.bind(this),13)
        },
        79: function () {
            //机器
            this.player.src="quanhuang/jiqi.gif";
        },
        38: function () {
            //跳跃
            this.player.src="quanhuang/advance.gif";
        },
    };
    Yagami.prototype.action = function (code) {
        if (skilllist[code]) {
            skilllist[code].call(this);
        }
    }
    Yagami.prototype.stop = function () {
        this.player.src="quanhuang/stand.gif";
        clearInterval(this.time);
    }
    var yage=document.getElementById("MC");
    var yaga=new Yagami(yage);
    document.onkeydown = play;
    document.onkeyup = function (e) {
        yaga.stop();
        document.onkeydown = play;
    }
    function play(e) {
        var code = e.keyCode;
        yaga.action(code);
        document.onkeydown=null;;
    }
</script>

下载位置http://download.csdn.net/download/weixin_38023551/10228295

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值