Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript touchmove与画布上的jquery一起从span获取文本_Jquery_Canvas_Touch_Move - Fatal编程技术网

Javascript touchmove与画布上的jquery一起从span获取文本

Javascript touchmove与画布上的jquery一起从span获取文本,jquery,canvas,touch,move,Jquery,Canvas,Touch,Move,我有下面的Javascript,mouseover工作正常,但是当我从支持的设备跟踪一行时,touchmove事件没有被触发,我在这里遗漏了什么?当我们使用touch事件悬停在跨度上时,有没有方法警告文本 函数init(){ setupDrawingCanvas(); } 函数setupDrawingCanvas(){ 变量x,y,ctx,down=false; var canvas=document.getElementById(“图形”); canvas.width=window.in

我有下面的Javascript,mouseover工作正常,但是当我从支持的设备跟踪一行时,touchmove事件没有被触发,我在这里遗漏了什么?当我们使用touch事件悬停在跨度上时,有没有方法警告文本


函数init(){
setupDrawingCanvas();
}
函数setupDrawingCanvas(){
变量x,y,ctx,down=false;
var canvas=document.getElementById(“图形”);
canvas.width=window.innerWidth-45;
canvas.height=window.innerHeight-45;
var maxLength=(canvas.width>canvas.height)?canvas.width:canvas.height;
移动功能(e){
如果(e.targetTouches.length==1){
e、 预防默认值();
ctx.beginPath();
ctx.moveTo(x,y);
ctx.lineTo(e.toucks[0].pageX-canvas.offsetLeft,e.toucks[0].pageY-canvas.offsetTop);
x=e.touchs[0].pageX-canvas.offsetLeft;
y=e.touchs[0].pageY-canvas.offsetTop;
ctx.stroke();
}
}
函数onTouchEnd(e){
如果(e.targetTouches.length==1){
e、 预防默认值();
removeEventListener(“touchmove”,onTouchMove,false);
removeEventListener(“touchend”,onTouchEnd,false);
}
}
功能启动(e){
如果(e.e.length==1){
e、 预防默认值();
x=e.touchs[0].pageX-canvas.offsetLeft;
y=e.touchs[0].pageY-canvas.offsetTop;
window.addEventListener(“touchmove”,onTouchMove,false);
window.addEventListener(“touchend”,onTouchEnd,false);
}
}
函数dropEvent(e)
{
e、 停止传播();
e、 预防默认值();
}
if(canvas.getContext){
ctx=canvas.getContext(“2d”);
ctx.strokeStyle=“#000000”;
canvas.addEventListener(“touchstart”,onTouchStart,false);
} 
var func=(函数(){
var num=parseInt($(this).text());
警报(“移动到”+num);
}); 
var$graph=$(“#graph”);
$('')
.addClass('圆')
.html(1)
.css({“顶部”:471,“左侧”:430})
.mouseover(func)
.insertAfter($graph);
$('')
.addClass('圆')
.html(2)
.css({“顶部”:451,“左侧”:410})
.mouseover(func)
.insertAfter($graph);
//当touchevent超过范围时,不会调用此函数
$('circle')。each.bind('touchmove',函数(e){
e、 预防默认值();
var num=parseInt($(this).text());
警报(“移动到”+num);
});
}
.圆圈{
背景:url('circle.png');
宽度:24px;
高度:24px;
文本对齐:居中;
字体大小:.8em;
线高:24px;
显示:块;
位置:绝对位置;
光标:指针;
颜色:#333;
z指数:100;
}
#图表{
左:200px;
顶部:20px;
位置:相对位置;
边框:1个点#ddd;
}



修改以下调用,将“圆圈”更改为“.circle”

$('.circle').each.bind('touchmove',function(e) { 
    e.preventDefault();
    var num =  parseInt($(this).text());
    alert ("moved over" + num );
});
<body onload="init();">
    <canvas id="graph" width="680" height="680"></canvas>
</body>
$('.circle').each.bind('touchmove',function(e) { 
    e.preventDefault();
    var num =  parseInt($(this).text());
    alert ("moved over" + num );
});