Represents the canvas component used to customize drawings.
Since: 1.0.0
Associated document: has.createCanvasContext
Name | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
type | string | - | No | Canvas type. The value can be 2d. |
canvas-id | string | - | No | Unique ID of the canvas component. |
disable-scroll | boolean | false | No | Whether to disable screen scrolling and pull-to-refresh. |
bindtouchstart | eventhandle | - | No | Event handler triggered when a touch action starts. |
bindtouchmove | eventhandle | - | No | Event handler triggered when a finger moves after touching. |
bindtouchend | eventhandle | - | No | Event handler triggered when a touch action ends. |
bindtouchcancel | eventhandle | - | No | Event handler triggered when a touch action is interrupted (for example, by locking the screen, switching applications, or receiving a call reminder). |
bindlongtap | eventhandle | - | No | Event handler triggered after a long press of 500 ms. Moving after a long press will not trigger screen scrolling. |
binderror | eventhandle | - | No | Event handler triggered when an error occurs, with detail.errMsg. |
hxml:
<canvas
canvas-id="canvas"
disable-scroll="{{false}}"
style="border: 3px solid blue">
</canvas>
<button bindtap="setFontSize">Set the font size</button> js:
Page({
setFontSize() {
var ctx = has.createCanvasContext('canvas');
ctx.setFontSize(20);
ctx.fillText('20', 20, 20);
ctx.draw();
}
})