How to Make Canvas Text Selectable?

后端 未结 9 1410
北荒
北荒 2020-12-02 13:46

Any suggestion is highly appreciated.

相关标签:
9条回答
  • 2020-12-02 14:22

    A simple answer would be: either use HTML or SVG instead of canvas. Unless you really need the degree of lowlevel control canvas offers.

    0 讨论(0)
  • 2020-12-02 14:23

    canvas is just a drawing surface. You render and the result is pixels. So, you'd need to track the positions of all text you have rendered to the canvas in a some kind of data structure which you'd process during mouse events.

    0 讨论(0)
  • 2020-12-02 14:24

    FabricJS now has the ability to interact with objects outside the canvas element - eg this demo shows a button that is linked to an image loaded in a canvas element.

    The same approach can be used in other libs such as Raphael by hooking any move event, getting the bounding box of the element and re-positioning the HTML element.

    0 讨论(0)
提交回复
热议问题