Attribute name | Type | Default value | Note |
canvas-id | string | - | Unique identifier of the canvas component |
disable-scroll | boolean | false | When moving within the canvas and a gesture event is bound, screen scrolling and pull-down refresh are prevented. |
bindtouchstart | eventhandle | - | Initiation of finger touch action |
bindtouchmove | eventhandle | - | Movement after finger touch |
bindtouchend | eventhandle | - | Termination of finger touch action |
bindtouchcancel | eventhandle | - | Finger touch action is interrupted, such as by an incoming call alert. |
bindlongtap | eventhandle | - | Upon a finger's prolonged contact of 500 ms, a long-press event is triggered. Following this, movement will not trigger screen scrolling. |
binderror | eventhandle | - | Upon encountering an error, an 'error' event is triggered, with detail = {errMsg: 'something wrong'}. |
<!-- canvas.wxml --><canvas style="width: 300px; height: 200px;" canvas-id="firstCanvas"></canvas><!-- When absolute positioning is used, the display level of the canvas following the document flow is superior to that of the preceding canvas --><canvas style="width: 400px; height: 500px;" canvas-id="secondCanvas"></canvas><!-- As the canvas-id is duplicated from the previous canvas, this canvas will not be displayed, and an error event will be dispatched to the AppService --><canvasstyle="width: 400px; height: 500px;"canvas-id="secondCanvas"binderror="canvasIdErrorCallback"></canvas>
// canvas.jsPage({canvasIdErrorCallback(e) {console.error(e.detail.errMsg)},onReady(e) {// Use wx.createContext to obtain the drawing contextconst context = wx.createCanvasContext('firstCanvas')context.setStrokeStyle('#00ff00')context.setLineWidth(5)context.rect(0, 0, 200, 200)context.stroke()context.setStrokeStyle('#ff0000')context.setLineWidth(2)context.moveTo(160, 100)context.arc(100, 100, 60, 0, 2 * Math.PI, true)context.moveTo(140, 100)context.arc(100, 100, 40, 0, Math.PI, false)context.moveTo(85, 80)context.arc(80, 80, 5, 0, 2 * Math.PI, true)context.moveTo(125, 80)context.arc(120, 80, 5, 0, 2 * Math.PI, true)context.stroke()context.draw()}})
Was this page helpful?