canvas画线
参考地址 https://segmentfault.com/q/1010000018554255
自写案例
画线 移入线条路径内高亮显示
html
1 | |
js
1 | |
模糊问题 把长宽高 写到 上面 不要写css 里
1 | |
坐标获取可用
1 | |
选中高亮核心属性
ctx.isPointInStroke(x,y)
// 测试后发现这个方法不适合,这个适用于图形范围
// if (ctx.isPointInPath(event.offsetX, event.offsetY)) {
// console.log(‘在区域上。。。。。。。。。。。’);
// }
// 测试后发现这个方法可以(主要用于边缘线
if (ctx.isPointInStroke(event.offsetX, event.offsetY)) {
console.log(‘在綫上。。。。。。。。。。。’);
ctx.stroke();
};
isPointInStroke 只能监听到最后一次画线的路径 所以要循环渲染
canvas 添加监听属性
1 | |
测试数据
1 | |
参考文献
参考 https://segmentfault.com/q/1010000018554255
https://blog.csdn.net/weixin_48963720/article/details/125219790
ctx.isPointInPath(80,80):判断点是否在上面路径的区域内。
ctx.isPointInStroke(80,50):判断点是否在上面路径的边缘线上
canvas画线
http://www.dwyblog.cn/2024/01/09/canvas画线/