XY Caret Coordinates inside a contenteditable div

前端 未结 1 1511
情话喂你
情话喂你 2021-01-13 17:05

I am looking for a way to get the caret x y coordinates inside a contenteditable div, in a similar manner to how you can get the mouse coordinates using window.event since I

1条回答
  •  余生分开走
    2021-01-13 17:37

    Here's one approach:

    Coordinates of selected text in browser page

    However, in some circumstances this will not give you coordinates, in which case you'd need to fall back to inserting an element at the caret, getting its position and removing the element again.

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