W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋:畫布
屬性說明:
屬性名 | 類型 | 默認(rèn)值 | 說明 |
---|---|---|---|
canvas-id | String | canvas 組件的唯一標(biāo)識(shí)符 | |
disable-scroll | Boolean | false | 當(dāng)在 canvas 中移動(dòng)時(shí)且有綁定手勢事件時(shí),禁止屏幕滾動(dòng)以及下拉刷新 |
bindtouchstart | EventHandle | 手指觸摸動(dòng)作開始 | |
bindtouchmove | EventHandle | 手指觸摸后移動(dòng) | |
bindtouchend | EventHandle | 手指觸摸動(dòng)作結(jié)束 | |
bindtouchcancel | EventHandle | 手指觸摸動(dòng)作被打斷,如來電提醒,彈窗 | |
bindlongtap | EventHandle | 手指長按 500ms 之后觸發(fā),觸發(fā)了長按事件后進(jìn)行移動(dòng)不會(huì)觸發(fā)屏幕的滾動(dòng) | |
binderror | EventHandle | 當(dāng)發(fā)生錯(cuò)誤時(shí)觸發(fā) error 事件,detail = {errMsg: ‘something wrong’} |
canvas 組件默認(rèn)寬度 300px、高度 225px。
示例:
<canvas canvas-id="myCanvas" class="canvas-testing" bindtouchend="canvas" bindtouchmove="mvcan">
</canvas>
// canvas.js
Page({
canvasIdErrorCallback: function (e) {
console.error(e.detail.errMsg);
},
onReady: function (e) {
const ctx = this.createCanvasContext('myCanvas');
// 或swan.createCanvasContext('myCanvas');
ctx.setFillStyle('#0f0f0f');
ctx.arc(100, 100, 50, 0, 2 * Math.PI);
ctx.fill();
ctx.beginPath();
ctx.setStrokeStyle('#0000ff');
ctx.moveTo(90, 70);
ctx.lineTo(70, 80);
ctx.lineTo(90, 80);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.setStrokeStyle('#0000ff');
ctx.moveTo(130, 70);
ctx.lineTo(110, 80);
ctx.lineTo(130, 80);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.setFillStyle('#00ff00');
ctx.arc(100, 100, 20, 0, 1 * Math.PI);
ctx.fill();
ctx.setFillStyle('#00ff00');
ctx.setFontSize(12);
ctx.fillText('haha', 165, 78);
ctx.moveTo(100, 50);
ctx.setStrokeStyle('#00ff00');
ctx.bezierCurveTo(100, 25, 75, 25, 50, 50);
ctx.stroke();
ctx.moveTo(100, 50);
ctx.quadraticCurveTo(75, 25, 50, 50);
ctx.stroke();
ctx.draw();
};
});
Bug & Tip:
1、canvas 組件是原生組件;
2、canvas 組件不能使用動(dòng)畫進(jìn)行控制;Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: