위챗 애플릿 좌회전 JS 코드 패키지

1963 단어
네트워크에 따라 약간의 봉인을 하여 최적화하였다.원리는 모두 같다.
var param={
    movMax: 120,
    movChangeTriger: 30,
    getCurrentTouchItem:function(e){  // 

    },
    refreshTouchList:function(e) {// 

    },

};



function touchStart  (e) { // 

    var currentItem = param.getCurrentTouchItem(e);
    currentItem.currentTouch = e.touches[0];
    currentItem.starttTouch = e.changedTouches[0];
}
function touchMove  (e) {


    var currentItem = param.getCurrentTouchItem(e);
    var currentTouch = currentItem.currentTouch;
    var nowTouch = e.touches[0];


    var movX = currentTouch.clientX - nowTouch.clientX;

    var isMovToLeft = movX > 0;



    movX += (currentItem.movX ? currentItem.movX : 0);

    if (movX > param.movMax || movX < 0) {
        return;
    }

    currentItem.currentTouch = nowTouch;
    if (isMovToLeft) {


        if (Math.abs(movX) > param.movMax) {

            movX = param.movMax;
        }

    } else {
        if (Math.abs(movX) < 0) {

            movX = 0;
        }
    }


    currentItem.stytle = "right:" + movX + "px;";
    currentItem.movX = movX;
    currentItem.isMovToLeft = isMovToLeft;

    param.refreshTouchList();



}

function touchEnd  (e) {


    var currentItem = param.getCurrentTouchItem(e);

    var movX = currentItem.movX;

    if (currentItem.isMovToLeft) {


        if (movX >= param.movChangeTriger) {

            movX = param.movMax;
        } else {
            movX = 0;
        }

    } else {
        if (movX < param.movMax - param.movChangeTriger) {

            movX = 0;
        } else {
            movX = param.movMax;
        }
    }

    currentItem.stytle = "right:" + movX + "px;";
    currentItem.movX = movX;

    param.refreshTouchList();

}



function setparam(param){
    param = param;
}


module.exports = {
    touchEnd: touchEnd,
    touchMove: touchMove,
    touchStart: touchStart,
    setparam: setparam,
}

좋은 웹페이지 즐겨찾기