【问题标题】:HTML5 - Drag N Drop with divs and inner-imagesHTML5 - 使用 div 和内部图像拖放
【发布时间】:2011-08-11 17:29:24
【问题描述】:
我有这种类型的元素:
<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>
我希望能够:
- 拖动整个 div,即使我单击 /anchorimage(在拖动之前)。
- 仍然正常响应锚点/图像点击(没有拖动)。
现在,当我点击它时,只有图像被拖动。
这是一个小提琴:http://jsfiddle.net/M5tBd/
【问题讨论】:
标签:
drag-and-drop
draggable
html5-video
【解决方案1】:
根据HTML5 Editor's Draft spec,带有 href 元素的图像和锚点都是默认可拖动的元素。您的锚点可能正在捕获 dragstart 事件,从而阻止 div 得到它。尝试在 <img> 和 <a> 元素上设置 draggable="false"。
<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>
你的小提琴甚至无法在 Ubuntu 下的 Chrome 中为我拖动 img 元素,所以除此之外你可能还有其他问题。