array
基础库 或更高版本; 若版本较低,建议采取 兼容处理。
主体: 企业支付宝小程序 、 个人支付宝小程序
获取当前虚线样式。
array
一组用于描述虚线的线段和间隔的数字。如 [10, 5] 代表虚线样式为 10 像素连续线段,5 像素间隔,以此重复。
代码示例
.js
.axml
page({
oncanvasready() {
my.createselectorquery().select('#canvas').node().exec(res => {
const canvas = res[0].node
let ctx = canvas.getcontext('2d')
ctx.setlinedash([10, 20, 5])
console.log(ctx.getlinedash()) // [10, 20, 5, 10, 20, 5]
// 绘制虚线
ctx.beginpath()
ctx.moveto(0, 50)
ctx.lineto(300, 50)
ctx.stroke()
ctx.setlinedash([10, 20])
console.log(ctx.getlinedash()) // [10, 20]
// 绘制虚线
ctx.beginpath()
ctx.moveto(0, 100)
ctx.lineto(300, 100)
ctx.stroke()
})
},
})
<canvas id="canvas" type="2d" onready="oncanvasready">canvas>