问题描述:

I am trying to disable the select while dragging an image. But it does not seems to work. I know similar questions has already been asked but none seems to work for me.

I also tried to enter this in css as suggested in many similar questions.

-webkit-touch-callout: none;/*for mobile*/

-webkit-user-select: none;/*for chrome*/

-khtml-user-select: none;/*for safari*/

-moz-user-select: none;/*for Mozilla*/

-ms-user-select: none;/*for mircosoft*/

-o-user-select: none;/*for opera*/

user-select: none;/*base css ,but not work in all browsers*/

FIDDLE

网友答案:

Use user-drag css option

img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none; 
}
网友答案:

Fixed it by setting e.dataTransfer.setDragImage to a transparent canvas of 1px and mouse drag still works

var c = document.getElementById("canvas");

document.getElementById("image").addEventListener("dragstart", function(e) {
    e.dataTransfer.setDragImage(c, 0, 0);
}, false);


document.getElementById("image").addEventListener("dragover", function(e) {
    e.preventDefault();
}, false);

FIDDLE

相关阅读:
Top