拖放 2 个放置目标
我正在寻找一个拖放示例,其中拖动项目有两个不同的区域,必须与两个可放置区域相匹配。
例子:
我希望蓝色拖动项目恢复,除非将其放置在其每个红色子项着陆的位置一个绿色区域。
理想情况下,我想使用 jquery ui (因为我有使用它的经验),但任何 javascript 库都可以,提前致谢。
I am looking for an example of drag and drop where the drag item has two distinct areas that have to match up with two droppable areas.
Example:
I would like the blue drag item to revert unless it is dropped in a position where each of its red children land on a green area.
Ideally I would like to use jquery ui (as I have experience with it), but any javascript library would be fine, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过使用
draggable
/droppable
选项的组合来实现此目的。给定这样的 HTML:(省略 CSS,我确实添加了一些规则,请参见下面的小提琴)。
你可以这样编写 JavaScript:
在这里查看:http://jsfiddle.net/andrewwhitaker/g6FKz/
注释:
div
。从例子中应该可以清楚地看出这一点。div
时,都会调用“drag”事件,该事件确定红色框是否位于绿色框内,并为可拖动div
分配一个valid
类。代码>div。可放置对象仅接受有效
可拖动对象。希望有帮助!
You can accomplish this by using a combination of
draggable
/droppable
options. Given HTML like this:(omitting CSS, I did add some rules, see in the fiddle below).
You can write JavaScript like this:
Check it out here: http://jsfiddle.net/andrewwhitaker/g6FKz/
Notes:
div
that contains those elements. This should be clear from the example.div
, the "drag" event is called, which determines if the red boxes are inside the green ones and assigns avalid
class to the draggablediv
. The droppable object only acceptsvalid
draggables.Hope that helps!