可以点击jQuery的可拖动父级开始拖动吗? [英] Can click on jquery draggable parent start drag?
问题描述
我有这样的标记
<div id="colorpicker-background">
<div id="colorpicker-selector"></div>
</div>
使用这样的JS:
$('#colorpicker-selector').draggable({
containment : $('#colorpicker-background'),
handle : $('#colorpicker-selector')
})
当用户onmousedown
在#colorpicker-background
上触发时,我将#colorpicker-selector
移动到鼠标按下的位置.问题是,即使选择器现在位于光标下方,用户也无法继续拖动.
When the user onmousedown
fires on #colorpicker-background
I move #colorpicker-selector
to where the mousedown is. The problem is, the user can't continue to drag even though the selector is now under the cursor.
我已尝试根据我已阅读且没有运气的各种帖子在#colorpicker-selector
上触发拖动,dragstart,mousedown,mousedown.draggable.
I have tried triggering drag, dragstart, mousedown, mousedown.draggable on #colorpicker-selector
based on all sorts of posts I've read and am having no luck.
这里的另一个用户遇到了同样的问题,但这是从6个月前开始的,没有答案,并且使用了不同的jQuery版本(因为此后有很多更新):
Another user here has had the same problem, but it's from 6 months ago, with no answer, and different jQuery versions ( as there have been many updates since then ): jquery start dragging object when clicked on the other
推荐答案
在mousedown
上,我绑定了函数updateSelector
updateSelector = function( e ) {
// update position yada yada...
$('#colorpicker-selector').trigger( e ); // make the dragging happen
}
这篇关于可以点击jQuery的可拖动父级开始拖动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!