HTML5 - 使用div和内部图像拖动N Drop

Dan*_*ges 2 drag-and-drop draggable html5-video

我有这种类型的元素:

<div draggable="true" id="item" style="margin:20px;background:red;height:400px;width:400px;">
    <a href="#" target="_blank">
        <img style="margin:40px;" src="http://www.placekitten.com/100/100" alt="">
    </a>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望能够:

  1. 拖动整个div,即使我单击/ anchorimage(拖动之前).
  2. 仍然可以正常响应锚点/图像点击(没有拖动).

现在,我点击它时只拖动图像.

这是一个小提琴:http://jsfiddle.net/M5tBd/

aar*_*ell 6

根据HTML5编辑器的草案规范,带有href元素的图像和锚点都是默认可拖动的元素.你的主播可能正在捕捉dragstart事件,阻止div获得它.尝试设置可拖动=你的"假" <img><a>元素.

<div draggable="true" id="item" style="margin:20px;background:red;height:400px;width:400px;">
<a href="#" target="_blank" draggable="false">
    <img style="margin:40px;" src="http://www.placekitten.com/100/100" alt="" draggable="false">
</a>
Run Code Online (Sandbox Code Playgroud)

你的小提琴甚至不能在Ubuntu下为我在Chrome中拖动img元素,所以你可能还有其他问题.