1

我正在使用鼠标事件来绘制自由线(使用 Raphael),它可以很好地处理鼠标事件,但不能处理触摸事件。如果是触摸事件,我是否需要将 event.pageX 替换为 event.screenX 或 event.clientX?

var board = $("#board");
board.bind("mousedown", _mousedownHandler);
        board.bind("touchstart", _mousedownHandler);
function _drawFreeLineBegin(x, y) {
        board.lineEl.path = _drawOptions.paper.path("M"
                + (x - _drawOptions.offset.left) + ","
                + (y - _drawOptions.offset.top));
        _setNewElementProperties(board.lineEl.path,
                Configuration.getProperties("freeLine"));
            board.bind("mousemove.mmu", _mousemoveHandler);
        board.one("mouseup.mmu", _mouseupHandler);
        board.bind("touchmove.mmu", _mousemoveHandler);
        board.one("touchend.mmu", _mouseupHandler);
    }
function _mousedownHandler(event) {
if(event.type == "touchstart"){
            event = event.touches[0];
        }
_drawFreeLineBegin(event.pageX, event.pageY);
return false;
}

    function _mousemoveHandler(event) {
    if(event.type == "touchmove"){
            event = event.touches[0];
        }
    board.lineEl.path
                        .attr(
                                "path",
                                board.lineEl.path.attr("path")
                                        + "L"
                                        + (event.pageX - )
                                        + ","
                                        + (event.pageY ));
                return true;

}

function _mouseupHandler(event) {
board.unbind(".mmu");
 board.lineEl.path = null;
    event.stopPropagation();
    event.preventDefault();
}
4

1 回答 1

1

想通了问题,我需要替换 event.touches[0]; 与 event.originalEvent.touches[0];

于 2013-07-18T15:42:43.783 回答