1

我在混淆如何在我的编码中放置 ontouch 时遇到了问题,因为我希望它在 ipad 上运行,下面是我的代码

    <script language="javascript">
function sig1()
{
    if(sig == null)
    {
        xclear('myCanvas');
    }
}

清除画布中的行的代码

<body id="main_body" class="no_guidelines" onload="sig1()" onmouseup="bodyonmouseup">

让画布具有填充样式颜色和功能

<canvas border=1 id="myCanvas" height=200 width=400 onmousedown="onmousedown()" onmouseup="onmouseup()" onmousemove="onmousemove()">Your browser does not support the application</canvas>

可以像签名一样画线的画布

var sig = null;
      var ele;
      function bodyonmouseup(e)
{
    var ele;
    ele = document.getElementById('myCanvas');
    ele.isDown = false;
}
function onmousedown(e)
{
    var ele,p;
    if (!e) e = window.event;
    ele = (e.srcElement);
    if (! ele) ele = e.target;
    ele.isDown = true; 
    ele.context = ele.getContext("2d");
    ele.context.lineWidth = 1;
    ele.context.beginPath();   
    ele.context.moveTo(e.offsetX,e.offsetY);
    sig.line = new Array();

    p = new Object();
    p.x = e.offsetX;
    p.y = e.offsetY;

    sig.p = p;
    sig.line[sig.line.length] = p;
    sig.lines[sig.lines.length] = sig.line;
}
function onmousemove(e)
{
    var ele,dx,dy,p;
    if (!e) e = window.event;
    ele = (e.srcElement);
    if (! ele) ele = e.target;
    if (! ele.isDown) return;
    ele.context.lineTo(e.offsetX,e.offsetY);
    ele.context.stroke();
    dx = e.offsetX - sig.p.x;
    dy = e.offsetY - sig.p.y;
    if (dx == 0 && dy == 0) return;
    sig.p = new Object();
    sig.p.x = e.offsetX;
    sig.p.y = e.offsetY;
    sig.line[sig.line.length] = sig.p;
}

所以我想知道我是否要同时保留onMouse和ontouch,我如何放置ontouch以便可以在ipad上绘制画布?请帮忙,很紧急

4

1 回答 1

0

使用这个 js。您的手指将成为您的鼠标。他们正在将所有触摸事件转换为鼠标事件。

jquery-ui-touch-punch

于 2012-06-21T07:37:25.943 回答