你如何关闭setDragImage [英] How do you turn off setDragImage
问题描述
就像它说的那样。你如何禁用拖动图像。我有一个浮动面板,拖动图像看起来很糟糕。 no-jquery please。
just as it states. how do you disable the drag image. I have a floating panel and the drag image looks very bad. no-jquery please.
推荐答案
来自 MDN :
如果节点是HTML
img
元素,HTMLcanvas
元素或XUL图像
元素,图像使用数据。否则,image
应该是一个可见节点,并且将从此创建拖动图像。
If the node is an HTML
img
element, an HTMLcanvas
element or a XULimage
element, the image data is used. Otherwise,image
should be a visible node and the drag image will be created from this.
从此可以看出,关闭拖动图像应该将空(但可见)元素传递给 setDragImage
。怎么样:
From this it would follow that to "turn off" the drag image you should just pass an empty (but visibile) element to setDragImage
. How about this:
// create an empty <span>
var dragImgEl = document.createElement('span');
// set its style so it'll be effectively (but not technically) invisible and
// won't change document flow
dragImgEl.setAttribute('style',
'position: absolute; display: block; top: 0; left: 0; width: 0; height: 0;' );
// add it to the document
document.body.appendChild(dragImgEl);
// your DataTransfer code here--assume we put it in a variable called 'dt'
dt.setDragImage(dragImgEl, 0, 0);
如果空< span>
没有由于某种原因,你总是可以使用< img src =blank.png/>
其中 blank.png
是一个透明的1像素PNG。希望有所帮助!
If an empty <span>
doesn't work for some reason you could always use <img src="blank.png"/>
where blank.png
is a transparent 1-pixel PNG. Hope that helps!
这篇关于你如何关闭setDragImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!