[英]Touchmove doesn't work with Google apps scripts html service
我试图让touchmove
事件注册一个使用 Google 应用程序脚本 html 服务编写的简单网络应用程序,以便我可以制作在 iPad 和桌面上运行的简单网络应用程序。
我所做的就是首先加载一个网页,它按预期工作:
function doGet() {
return HtmlService.createHtmlOutputFromFile('test page');
}
然后我在html页面上创建了一个简单的画布:
<html>
<canvas id="canvas" width="200" height="200" style="border:1px solid #000000;">
</canvas>
<script>
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
ctx.font = "bold 12px sans-serif";
ctx.fillStyle="black";
ctx.fillText("TEST",50,50);
canvas.addEventListener("touchmove",testme,false);
function testme(e) {
e.preventDefault();
alert("testme");
}
</script>
</html>
这只是我尝试过的最新变体。 在此示例中,绑定click
或mousedown
或mousemove
在桌面上都可以正常工作。 但是,尝试使用touchstart
或touchmove
在 iPad 上没有任何作用。 我已经在 iPad 上对 Chrome 和 Safari 进行了测试。
我也尝试添加类似的东西:
document.addEventListener("touchmove",doPreventDefault,false);
并有一个调用preventDefault()
的简单函数,但这也无济于事。
我做错了什么,还是我必须做一些不同的事情,因为它是谷歌应用程序脚本 html 服务?
我现在已经尝试过 jQuery(只是阅读了如何去做),但它似乎仍然无法在 iPad 上正常工作:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<p>Test</p>
<br><br>
</body>
<canvas id="canvas" width="200" height="200" style="border:1px solid #000000;">
</canvas>
<script>
$(document).ready(function() {
$("#canvas").bind('touchstart',function(e) {
alert("Hello world!");
});
$("p").mousedown(stuff);
$('#canvas').touchmove(onMove);
});
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
ctx.font = "bold 12px sans-serif";
ctx.fillStyle="black";
ctx.fillText("TEST",50,50);
function onMove(e) {
alert("testing");
}
function stuff(e) {
alert("Stuff");
}
</script>
</html>
mousedown
事件工作正常,并且它的事件与触摸一起工作 - 事实上, mousedown
和mouseup
似乎与 iPad 上的触摸相关联。 但是mousemove
不起作用, touchmove
或touchstart
或touchend
。 如上所示,我尝试使用 bind 和更直接的方法。
有什么我做错了使这项工作?
您可以在 Caja 问题跟踪器上添加功能请求以将这些事件列入白名单。 他们目前不在白名单上。
阅读 htmlservice 文档。 除非您使用像 jquery 这样的与 caja 兼容的方式,否则您无法操纵 dom。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.