2011-08-11 22 views
2

我有這種類型的元素:HTML5 - 將N個液滴與申報單和內部圖像

<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> 

我希望能夠到:

  1. 將整個DIV,即使我點擊在/ anchorimage上(拖動之前)。
  2. 仍然正常響應錨點/圖像點擊(沒有拖動)。

現在,當我點擊它時,只有圖像被拖動。

這裏有一個小提琴:http://jsfiddle.net/M5tBd/

+0

讓我們去找朋友。 –

+0

現在我很絕望。 –

回答

5

按照該HTML5 Editor's Draft spec,圖片和美女主播與A 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下拖動img元素爲我在Chrome中,所以你可能有除此之外的其他問題。

+0

我在這裏問過同樣的問題:http://stackoverflow.com/questions/29084387/how-to-html5-drag-an-element-that-has-a-link-in-it?noredirect=1#評論46401999_29084387你可能會在那裏回答,我會接受它,因爲這裏的OP似乎不再在意。 – ohcibi