你如何关闭setDragImage [英] How do you turn off setDragImage

查看:341
本文介绍了你如何关闭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 元素,HTML canvas 元素或XUL 图像元素,图像使用数据。否则, image 应该是一个可见节点,并且将从此创建拖动图像。

If the node is an HTML img element, an HTML canvas element or a XUL image 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆