在 jQuery 中控制可拖动移动
如何控制 jquery 中可拖动对象的移动?
我需要做一些类似于“捕捉到网格”的事情,其中可拖动移动每个“x”和“y”像素
我不能使用“grid:[x,y]”(2D),因为我需要进行拖动在等距网格(3D)上(我稍后将开发网格,我首先需要控制拖动)
例如:当我开始拖动时,可拖动不应该移动,当“x ”和“y”在某些条件下,
提前致谢!
how can I control de movement of a draggable in jquery?
I need to do something similar to the "snap to grid" where the draggable moves every "x" and "y" pixels
I can't use "grid: [x, y]" (2D) because I need to make the drag on an isometric grid (3D) (I will develop the grid later, I first need to controll the drag)
for example: when I start the dragging, the draggable shouldn't move, it has to snap to another position when the "x" and "y" are under certain conditions
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 .draggable() 函数中固有的选项 http://jqueryui.com/demos/draggable/< /a>
基本上,它表示您需要将
snap
选项设置为true
,如下所示:snapMode "...确定可拖动元素将捕捉到的捕捉元素的哪些边缘。如果 snap 为 false,则忽略。可能的值:'inner'、'outer'、'both'。”
snapTolerance 是“...距应发生捕捉的捕捉元素边缘的距离(以像素为单位)”。
或者尝试使用
网格
选项。创建它是为了完全执行您想要的操作:“...网格将拖动助手捕捉到网格,每个 x 和 y 像素。数组值:[x, y]
代码示例:
使用指定的网格选项初始化可拖动对象。
在初始化后获取或设置网格选项。
希望这对您有帮助。
Try using the options inherent in the .draggable() function at http://jqueryui.com/demos/draggable/
basically it says you need to have the
snap
option set totrue
like this:snapMode "...determines which edges of snap elements the draggable will snap to. Ignored if snap is false. Possible values: 'inner', 'outer', 'both'."
And snapTolerance is "...The distance in pixels from the snap element edges at which snapping should occur."
Or try using the
grid
option. This is created to do exactly what you want:"...Grid snaps the dragging helper to a grid, every x and y pixels. Array values: [x, y]
Code examples":
Initialize a draggable with the grid option specified.
Get or set the grid option, after init.
Hopefully this helps you.
好的,我找到了我要找的东西!
在此链接中是我需要的代码片段,
代码是这样的:
/ /inside Drag: function(event, ui)
我更改了一些常量以适应我的网格...
ok, I've found what I was looking for!
in this link was the piece of code that I needed
the code is this:
//inside drag: function(event, ui)
I changed some of the constants to adjust to my grid...