[英]Lock mouse position when dragging element with jQuery UI sortable
I use jQuery UI sortable plugin to let users reorder divs with in a container. 我使用jQuery UI sortable插件让用户在容器中对div重新排序。
In the plugin's settings i set axis:"y"
to constrain the dragging movement to a vertical movement only. 在插件的设置中,我将
axis:"y"
为仅将拖动运动限制为垂直运动。
When the user drags the div
the mouse position is staying the same (relative to the dragged div
) vertically but horizontally the mouse moves freely and (to my opinion) it gives a less "firm" / "stable" ui experience and i want the mouse to stay on the same position (relative to the div
) while dragging. 当用户拖动
div
,鼠标的位置在垂直方向上保持不变(相对于所拖动的div
),但在水平方向上鼠标可以自由移动,并且(我认为)它给人的“坚定” /“稳定”的ui体验较少,我希望拖动时鼠标保持在相同位置(相对于div
)。
Any ideas how to do that? 任何想法如何做到这一点?
Note: when the sorting isn't constrain to to a vertical movement only the mouse is locked to the first position natively. 注意:当排序不限于垂直移动时,仅将鼠标本地锁定在第一个位置。
controlling mouse position with JS is tough to do and not advisable. 用JS控制鼠标位置很难,也不建议这样做。 Still, if you want to do this you should take a look at the Pointer Lock API, although I am not sure it will accomplish what you're looking for.
尽管如此,如果您想这样做,您应该看一下Pointer Lock API,尽管我不确定它能否完成您要寻找的东西。
Kind regards, 亲切的问候,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.