JQuery 拖放保存位置
我使用 JQuery 拖放来创建在 www.bbc.com 等网站上使用的仪表板。拖拽控件后是否可以保存控件的坐标?如果是这样,有人有可以推荐的网站或文章吗?
谢谢!
I'm using the JQuery drag and drop to create a dashboard used on websites such as www.bbc.com. Is it possible to save the coordinates of the control after dragging and dropping the controls? if so, anyone have a website or article they would recommend?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您只想要控件的坐标,则可以使用
http://api.jquery.com/offset/ 拖动停止后然后保存这些坐标到数据库。
但是,如果您的元素捕捉到网格,您可能需要计算该元素位于哪个网格列以及该列中的哪个位置。
If you just want the coordinates of the controls you can just use
http://api.jquery.com/offset/ after the dragging has stopped and then saves those coordinates to a database.
But if your elements snap to a grid you might want to calculate which grid column and which position in that column the element is.
你想把他们救到哪里?
您可以编写一个函数来保存容器内的位置,当用户完成移动控件时,会触发一个事件:
您可以在其中使用 offset 函数获取控件位置。
问候
Where do you want to save them?
You can write a function to save the position inside the container, when a users finish to move the controls an event is fired:
There you can get the controls position using the offset function.
Regards
您正在寻找 ui.position 属性。
该事件可以绑定在可拖动方法中,但为了清楚起见,我将其保留为这样。
更多信息
You're looking for the ui.position attribute.
The event can be bound within the draggable method but I've left it like this for clarity.
More Information
这将帮助您的拖动控件在释放拖动时移动到其原始位置
this will help your drag control move to its original position when drag is released
您不能在 drop 上运行一个函数,使用 ajax 将相关控件的坐标和大小发送到服务器并保存吗?
如果是“正常”拖放,那么您就有一个可以使用的
stop
功能。Could you not run a function on the drop that sends the coordinates and size of the control in question using ajax to the server and save it?
If it's the "normal" drag and drop then you have a
stop
function that you could use.拖放
drag and drop