boolean canvascontext.ispointinpath(path2d path, number x, number y, string fillrule)
若版本较低或需要适配多个客户端,建议采取 兼容处理 。
基础库 2.9.79 或更高版本;
支小宝客户端 支持
安诊儿客户端 支持
主体: 企业支付宝小程序 、 个人支付宝小程序
检测一个点是否在路径的填充范围内。
此 api 共有 4 种用法:
ispointinpath(number x, number y)
ispointinpath(number x, number y, string fillrule)
ispointinpath(path2d path, number x, number y)
ispointinpath(path2d path, number x, number y, string fillrule)
number x
要检测的点的 x 轴坐标。
number y
要检测的点的 y 轴坐标。
string fillrule
填充规则。可选,默认为 nonzero。
枚举值 | 描述 |
---|---|
nonzero | |
evenodd |
path2d path
若传入,会基于 path2d 中的路径检测,否则基于画布当前路径检测点是否在路径的填充范围内。
基于当前路径判断
.js
.axml
page({
onready() {
const ctx = my.createcanvascontext('canvas');
ctx.rect(10, 10, 50, 50)
ctx.rect(80, 80, 50, 50)
ctx.fill()
this.ctx = ctx
ctx.draw();
},
onmove(e) {
let { x, y } = e.changedtouches[0]
console.log(this.ctx.ispointinpath(x, y))
}
})
<canvas id="canvas" ontouchmove="onmove" disable-scroll>canvas>
画布的当前路径中有两个矩形路径已填充黑色,当手指移动到矩形路径被填充区域内时,接口返回 true,否则返回 false。
默认标题0