Detect direction of user selection with javascript

后端 未结 5 1087
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 05:43

I am emulating text editor in my project with custom caret, but native selection. Is there any way how to detect in which direction did user select the text? Lets say, that

5条回答
  •  渐次进展
    2020-12-30 06:29

    As far as I'm aware there is no property or event native to Javascript that will tell you the direction. This site details how to track mouse direction, you can tweak it to your needs.

    Essentially, as long as you can retrieve the mouse position (with either loc.pageX or Y, or event.clientX or Y), you may be able write your own functions to track the direction based on position and time.

    In your case you'd probably only want to capture this when the user has text 'selected', ie on the mousedown event.

提交回复
热议问题