jQuery Draggable:如何限制可拖动区域? [英] jquery draggable: how to limit the draggable area?

查看:633
本文介绍了jQuery Draggable:如何限制可拖动区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可拖动的对象(div)和一些可拖放的对象(表TD).我希望用户将我的可拖动对象拖动到那些可放置的TD之一.

I have a draggable object (div), and some droppable ones (table TD's). I want the user to drag my draggable object to one of those droppable TD's.

我通过以下方式启用可拖放:

I enable draggable and droppable this way:

$(".draggable").draggable();
$(".droppable").droppable();

问题在于,用户可以将div拖动到屏幕上的任意位置,包括可放置区域之外.

The problem is that with this the user can drag the div anywhere on the screen, including out of the droppable area.

如何限制可拖动对象的边界区域?

How can I limit the boundary area for the draggable object?

推荐答案

使用包含"选项:

jQuery UI API-可拖动的小部件-包含

文档说它只接受以下值:'parent''document''window'[x1, y1, x2, y2],但我似乎还记得它也会接受诸如"#container"之类的选择器.

The documentation says it only accepts the values: 'parent', 'document', 'window', [x1, y1, x2, y2] but I seem to remember it will accept a selector such as '#container' too.

这篇关于jQuery Draggable:如何限制可拖动区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆