植物大战僵尸JS 实现地图向左移动 后向右返回至原来位置

var map_left=0;
var map_right=map_left+1;
var state=map_left;

this.run = function () {
    switch(state){
        case map_left:
            imgX = imgX - 5;
            if (imgX <= -400) {
                state=map_right;
            }
            map.style.left = imgX + "px";
            break;
        case map_right:
            imgX = imgX + 5;
            if (imgX >=  0) {
                imgX =  0;
            }
            map.style.left = imgX + "px";
    }

猜你喜欢

转载自blog.csdn.net/junling_xhu/article/details/80976838