Richard Richard - 6 months ago 65
Javascript Question

How do you turn off setDragImage

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.


From MDN:

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.

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
  'position: absolute; display: block; top: 0; left: 0; width: 0; height: 0;' );

// add it to the document

// your DataTransfer code here--assume we put it in a variable called 'dt'

dt.setDragImage(dragImgEl, 0, 0);

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!