How to detect if mouse position is hovering

前端 未结 3 616
太阳男子
太阳男子 2021-01-07 12:52

I have this discussion which indicates how to make a pencil tool.

How can I detect whether the mouse is hovering on drawn area/points/images using the pencil tool? T

3条回答
  •  隐瞒了意图╮
    2021-01-07 13:09

    You can get the (per pixel) image data from a canvas: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData. Then check if the mouse is hovering over a green pixel.

提交回复
热议问题