HTML5之觸摸事件(touchstart、touchmove和touchend)

item_list = $('#incomeStatement')[0];//要加載的塊
item_list.addEventListener('touchstart', touchstart, false);
item_list.addEventListener('touchmove', touchmove, false);
item_list.addEventListener('touchend', touchend, false);
function touchstart(e) {
        touch_start_y = e.changedTouches[0].clientY;
    }

    function touchmove(e) {
        //上拉到頂
        if($(document).scrollTop() <0){
            if (e.changedTouches[0].clientY > touch_start_y) {
                var change = e.changedTouches[0].clientY - touch_start_y;
//                    e.preventDefault();
            }
        }
        //下拉到底
        else if($(document).scrollTop() >= $(document).height() - $(window).height()){
            if (e.changedTouches[0].clientY < touch_start_y) {
                var change = touch_start_y - e.changedTouches[0].clientY;
                //加載數據
                init_income_statement();
//                    e.preventDefault();
            }
        }
    }

    function touchend(e) {
        touch_start_y = -1;
    }
相關文章
相關標籤/搜索