【发布时间】:2011-02-24 10:56:19
【问题描述】:
编辑:演示代码位于此处的“平行四边形资源管理器”选项卡中:http://atmdev01.procloud.net/geometry_tools9/
所以我在文档加载时调用以下 javascript 函数来绘制平行四边形的周长,它可以正常工作。问题是当我从 touchmove 处理程序调用该函数以允许 iPad 用户调整平行四边形的大小时,画布没有正确重绘形状。事实上,它根本没有反应。我已经运行了一些警报来验证这个函数是否真的在运行并且确实是。
这可能是我清除画布的方式(“canvas.width = canvas.width + 0”方法)或只是 iPad 上的刷新率问题?
有趣的是,它在使用 mousemove 的桌面浏览器中完美运行,但在使用 touchmove 的 iPad 上却不行。请指教...
(代码中的“角”是用户可以触摸和拖动以调整平行四边形大小的区域)
this.drawSides = function() {
var order = [1, 2, 4, 3];
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var firstCorner = this.getCornerObj(1);
var secondCorner = this.getCornerObj(2);
var firstCornerOpp = this.getCornerObj(firstCorner.opp);
var secondCornerOpp = this.getCornerObj(secondCorner.opp);
/* Clear the canvas and draw a parallelogram with the provided corners */
canvas.width = canvas.width + 0; //clears the canvas faster than clearRect
ctx.beginPath();
for (i in order) {
if (i < order.length) {
var cornerObj = this.getCornerObj(order[i]);
if (order[i] > 1) {
var prevObj = this.getCornerObj(order[i-1]);
ctx.moveTo(prevObj.x + (prevObj.width)/2, prevObj.y + (prevObj.height)/2);
ctx.lineTo(cornerObj.x + (cornerObj.width)/2, cornerObj.y + (cornerObj.height)/2);
}
}
}
ctx.lineTo(firstCorner.x + (firstCorner.width)/2, firstCorner.y + (firstCorner.height)/2);
ctx.strokeStyle = "#300";
ctx.stroke();
}
【问题讨论】:
-
提供一部分代码很好。不过,更好的办法是在线托管一个可重现的精简测试用例,显示所有部件的交互。
-
@Phrogs 这是一个演示:atmdev01.procloud.net/geometry_tools9
-
谢谢;当我回到我的 iPad 时,我会看看。 (如果你拼错了我的名字,我会在昨晚看到这个。;)
标签: javascript ipad html canvas touch