带有文本区域的可拖动 Div。阻力问题
我有一个 div,里面有一个文本区域。主 div 是可拖动的并且工作正常,但我无法在单击其中的文本区域时拖动 div。即使我从div内的文本区域拖动它,有没有办法拖动div?
这是我如何使我的 div 可拖动
$('.speech_bubble').draggable(
{
containment: $('#dropHere')
});
谢谢
I have a div with a textarea in it. The main div is draggable and works fine, but I'm unable to drag the div while clicking on the textarea in it. Is there a way to drag the div even if I drag it from the textarea inside the div?
Here is how I make my div draggable
$('.speech_bubble').draggable(
{
containment: $('#dropHere')
});
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是因为可拖动的取消选项。默认值为':input,option',这意味着从文本区域开始拖动将被取消。尝试使用该选项。
It is becuase of the cancel option of the draggable. The default is ':input,option', that means that starting the drag from the textarea will be cancelled. Try playing with that option.
尝试添加以下样式:
然后,您可以在拖动
div
标记底部的同时拖动textarea
。Try adding the following styles:
You can then drag the
textarea
while you drag on the bottom side of thediv
tag.您可以尝试使用 onmouseover 事件在文本区域上创建一个屏幕(不可见 div),然后通过双击事件删除屏幕来检测用户是否想要编辑文本。
You can try creating a screen (Invisible div) over the textarea using the onmouseover event, then detect if the user wants to edit the text by removing the screen via double click event.
我知道这是一个非常古老的问题,但我认为最好回答我刚刚正在研究的确切问题(即而不是创建一个新问题)。答案是指 dioslaska 的解决方案,即通过在事件处理程序内的预期文本区域上添加一个额外的 .focus() 调用来清除取消属性(例如单击)。我在解决方案中使用了双击来区别于简单地移动对象。
用于选择:
目前看起来有一个错误(http://bugs.jqueryui.com/ticket/4986)。解决方法是,在事件处理程序中使用 destroy 禁用可拖动对象,并在模糊()(或其他禁用事件处理程序)函数中重新创建可拖动对象。
I know this is a very old question, but I thought it would be better to answer the exact question I had just been working on (i.e. instead of creating a new one). The answer refers to dioslaska's solution of clearing the cancel attribute with adding one additional .focus() call on the intended textarea inside your event handler (say a click). I used a double click in my solution to differentiate from simply moving my object.
For selection:
Currently it looks like there is a bug (http://bugs.jqueryui.com/ticket/4986). For a workaround, in the event handler disable the draggable by using destroy, and in the blur() (or other disabling event handler) function recreate the draggable.