简体   繁体   English

如何通过 jQuery UI 使整个 DOM 可拖动和调整大小?

[英]How to make entire DOM draggable & resizable via jQuery UI?

Is there a way to "activate" an entire DOM to be draggable and resizable using jQuery UI?有没有办法使用 jQuery UI“激活”整个 DOM 以使其可拖动和调整大小? I then want to save the user's new positions in HTML5's data attribute to recreate the page later.然后我想将用户的新位置保存在 HTML5 的数据属性中,以便稍后重新创建页面。

Imagine this same page you're looking at to be "activated" when you just hover, click, drag, and resize all the visible elements around (snapping would be super nice.)?想象一下,当您只是 hover、单击、拖动并调整周围所有可见元素的大小时,您正在查看的同一页面被“激活”(捕捉会非常好。)? Any advice or idea on this?对此有何建议或想法?

Making literally every div/span as drag and droppable is non-sensable.让每个 div/span 都可以拖放是不明智的。 What we has humans easily observe as a atomic "unit" (like the 'javascript' tag box) is not so obvious internally in the HTML structure.在 HTML 结构内部,我们人类很容易观察到的原子“单元”(如“javascript”标签框)并不那么明显。 So you may have to do some thinking and decide what you want included in "everything" that becomes Drag and droppable.因此,您可能需要进行一些思考并决定您希望将哪些内容包含在可拖放的“所有内容”中。 And at that point, you can just name all those elements with a "dd" class and use that.那时,您可以使用“dd”class 命名所有这些元素并使用它。

Like Thr4wn said, if you give each element that should move a class, then you can give each member of that class a function that updates its location when it changes.就像 Thr4wn 所说,如果你给每个应该移动 class 的元素,那么你可以给那个 class 的每个成员一个 function,当它改变时更新它的位置。 I suggest using 960.gs as a grid to remember locations.我建议使用960.gs作为网格来记住位置。

This way you can each objects classes as html5 data.这样,您可以将每个对象类作为 html5 数据。

It's pretty simple, just do this:这很简单,只需这样做:

$('*').draggable();

Not really sure why you would want to do this.不太确定您为什么要这样做。

if you really want to you could use the $("*") selector.如果你真的想要,你可以使用$("*")选择器。 but I would not suggest it...但我不会建议它...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM