亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

畫布繪圖觸摸不是繪圖

畫布繪圖觸摸不是繪圖

一只甜甜圈 2021-11-18 20:03:50
如果我在 lineTo() 和 moveTo() 上輸入一個位置,我有一條線,但是如果我給 touchstart 和 touchmove 位置什么都不會發生,我有機器人控制臺錯誤來幫助我touchStart(e){  this.touchDessiner(e.changedTouches[0].pageX, e.changedTouches[0].pageY)  console.log(e.changedTouches[0].pageX, e.changedTouches[0].pageY);}touchMove(e){  e.preventDefault();  this.touchDessiner(e.changedTouches[0].pageX, e.changedTouches[0].pageY)  console.log(e.changedTouches[0].pageX, e.changedTouches[0].pageY)}  touchDessiner(x, y){    this.cont.lineWidth = 2;    this.cont.strokeStyle = "#000";    this.cont.beginPath();    this.cont.moveTo(x, y);    this.cont.lineTo(x, y);    this.cont.stroke();  }
查看完整描述

1 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

下面是畫線的正確順序:


在 TouchStart 上:

1. 開始一條新路徑(從畫布上提起筆)

2. 將筆移到這里


在 TouchMove 上:

3. 在筆仍然接觸畫布的情況下,將筆移到此處


canvas = document.getElementById("can");

cont = canvas.getContext("2d");


function touchStart(e){

  this.cont.beginPath();

  this.cont.moveTo(e.changedTouches[0].pageX, e.changedTouches[0].pageY);

}


function touchMove(e){

  e.preventDefault();

  this.touchDessiner(e.changedTouches[0].pageX, e.changedTouches[0].pageY)

}


function touchDessiner(x, y){

  this.cont.lineWidth = 2;

  this.cont.strokeStyle = "#000";

  this.cont.lineTo(x, y);

  this.cont.stroke();

}


window.addEventListener("touchstart", touchStart);

window.addEventListener("touchmove", touchMove);

<!DOCTYPE html>

<html>

<body>

  

  canvas

  <canvas id = "can" style = "border: 1px solid black; position:absolute; left:0px; top:0px;"> </canvas>


</body>

</html>


查看完整回答
反對 回復 2021-11-18
  • 1 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號