[英]HTML5 drag & drop: The dragged element content is missing in Webkit browsers
I'm trying to implement something similar to a cart where you can drop items from a list. 我正在尝试实现类似于购物车的东西,您可以从列表中删除项目。 This items ( <li>
elements) has some elements inside (divs, span, and that stuff). 这个项目( <li>
元素)里面有一些元素(div,span和那些东西)。 The drag and drop itself works great. 拖放本身效果很好。 But the dragged element's image doesn't show its content in Webkit browsers. 但拖动元素的图像不会在Webkit浏览器中显示其内容。
My list element has a border an a background color. 我的列表元素有一个边框和一个背景颜色。 In Firefox, the image is the whole item. 在Firefox中,图像是整个项目。 In Webkit browsers, only the dragged element without content. 在Webkit浏览器中,只有拖动的元素没有内容。 I see the background and border, but without text inside. 我看到了背景和边框,但里面没有文字。
I tried to make a copy of the element and force it to be the image, but doesn't work. 我试图制作元素的副本并强制它成为图像,但不起作用。
var dt = ev.originalEvent.dataTransfer;
dt.setDragImage( $(ev.target).clone()[0], 0, 0);
I have a simplified example that exhibit the same behavior: http://jsfiddle.net/ksnJf/1/ 我有一个展示相同行为的简化示例: http : //jsfiddle.net/ksnJf/1/
Use addElement : 使用addElement :
dt.addElement(this);
instead in the dragstart event. 而是在dragstart事件中。 But beware transparent background :) 但要注意透明背景:)
BTW, why would you don't use code from example 1 or even example 2 ? 顺便说一句,你为什么不使用示例1甚至示例2中的代码?
UPD: For Webkit need to use webkitUserDrag property or equivalent CSS UPD:对于Webkit,需要使用webkitUserDrag属性或等效的CSS
-webkit-user-drag: element;
-webkit-user-select:none;
There is an example of copying LI elements from UL to DIV. 有一个将LI元素从UL复制到DIV的例子 。
I've just test it. 我只是测试一下。 It works! 有用! But all code in the JS, i have tested in any way or another, and didn't work for me. 但是JS中的所有代码,我已经以任何方式进行了测试,并且对我没有用。 And then, I saw the difference. 然后,我看到了区别。 The used as a wrapper do the magic. 用作包装的魔法。 This works 这有效
<li draggable="true" class="course" data-id="1">
<div class="content">
<div class="name">Agua Mineral</div>
<div class="price">1.50</div>€
</div>
</li>
This doesn't 事实并非如此
<li draggable="true" class="course" data-id="1">
<div class="name">Agua Mineral</div>
<div class="price">1.50</div>€
</li>
I don't know if its a bug or its intentional, but anyway it's inconsistent in different browsers. 我不知道它是一个bug还是它的故意,但无论如何它在不同的浏览器中都是不一致的。 I'll ask on webkit group. 我会问webkit小组。
Thanks! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.