我最近一直在学习 HTML 画布,并制作了一个在桌面上完美运行的简单绘图应用程序。但在移动设备上我无法绘制连续的线,只能绘制单个点。知道我做错了什么吗?链接到我的 codepen 版本
let color = "black";
let strokeSize = 10;
function changeColorAndSize(data, width) {
color = data;
strokeSize = width;
}
window.addEventListener("load", () => {
const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext("2d");
//resizing
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
//variables
let painting = false;
//functions
function startPosition(e) {
painting = true;
draw(e);
}
function endPosition() {
painting = false;
ctx.beginPath();
}
function draw(e) {
if (!painting) {
return;
}
e.preventDefault();
ctx.lineWidth = strokeSize;
ctx.lineCap = …Run Code Online (Sandbox Code Playgroud)