2018-08-10

2018-08-10  本文已影响0人  浪巅

1.

function initEle() {

    context.restore();

    context.save();   

2.

let datas = []

function fakeData(count){

    var item = new Object();

    myInfo.avatarUrl = 'sprite0.jpg';

    myInfo.nickName = '宏伟'+'(我)';

    myInfo.score = 100;

    myRank = 8848;

    for (var i = 0; i < count ; ++i){

        var item = new Object();

        item.avatarUrl = 'sprite.png'

        item.nickname = '宏伟'+i

        item.score = ''+i

        datas.push(item)

    }

}

function friends(){

    initEle();

    fakeData(20);

    initRanklist(datas);

    drawMyRank();

    window.addEventListener('mousedown',onDown);

}

function stopShow(){

    window.removeEventListener('mousedown',onDown);

    window.removeEventListener('mousemove',onMove);

    window.removeEventListener('mouseup',onUp);   

}

function onDown(e) {

    window.addEventListener('mousemove',onMove);

    window.addEventListener('mouseup',onUp);

}

let startY = undefined, moveY = 0;

// 触摸移动事件

function onMove(e) {

    // let touch = e.touches[0];

    // 触摸移动第一次触发的位置

    if (startY === undefined) {

        startY = e.clientY + moveY;

    }

    moveY = startY - e.clientY;

    reDrawItem(moveY);

}

function onUp(e) {

    startY = undefined;

    if (moveY < 0) { // 到顶

        moveY = 0;

    } else if (moveY > itemCanvas.height - 590) { // 到底

        moveY = itemCanvas.height - 590;

    }

    reDrawItem(moveY);

    window.removeEventListener('mousemove',onMove);

    window.removeEventListener('mouseup',onUp);   

};

上一篇下一篇

猜你喜欢

热点阅读