Can click on jquery draggable parent start drag?

感情迁移 提交于 2019-11-30 19:20:14

问题


I have markup like this

<div id="colorpicker-background">
  <div id="colorpicker-selector"></div>
</div>

With JS like this:

$('#colorpicker-selector').draggable({
  containment : $('#colorpicker-background'),
  handle      : $('#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.

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.

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


回答1:


On mousedown I bind the function updateSelector

updateSelector = function( e ) {

 // update position yada yada...

 $('#colorpicker-selector').trigger( e ); // make the dragging happen

}


来源:https://stackoverflow.com/questions/5239649/can-click-on-jquery-draggable-parent-start-drag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!