简体   繁体   English

拖放:Chrome中的游标

[英]Drag & Drop : Cursor in Chrome

My problem is that in Chrome the cursor doesn't move with the draggable item. 我的问题是在Chrome中,光标不会随着可拖动项移动。 It works fine in IE. 在IE中工作正常。 I have jquery and jquery-ui 1.11.1 and this the script I am using 我有jquery和jquery-ui 1.11.1,这是我正在使用的脚本

function allowDrop(ev) {
    ev.preventDefault();
}


function drag(ev) {
    ev.target.innerHTML += ' '; // Add space so that there is no kerning...
    ev.dataTransfer.setData("Text", ev.target.id);
}

function drop(ev) {
    ev.preventDefault();
    var data = ev.dataTransfer.getData("Text");
    ev.target.parentNode.replaceChild(document.getElementById(data), ev.target);
    document.getElementById(data).className = " ";
}

function drop(ev)
    {
      ev.preventDefault();
      var data=ev.dataTransfer.getData("Text");

      if(ev.target.getAttribute('data-drop') == data)
        ev.target.appendChild(document.getElementById(data));

    }

Maybe something is missing. 也许缺少了一些东西。 Help would really be appreciated 帮助将不胜感激

The problem is the drag image ('shadow') being moved to the corner of the #word , correct? 问题是拖动图像(“阴影”)被移到#word的角落,对吗?

It looks like Chrome is calculating the position wrong, may be because the <span> and <center> tags, I guess... Chrome似乎在计算位置错误,可能是因为<span><center>标签,我想...

You can fix that using the setDragImage method, set the DragImage to be the target of the event and set the offset according to the click position, this will force Chrome to render it right: 您可以使用setDragImage方法修复该问题,将setDragImage设置为事件的target ,并根据点击位置设置偏移量,这将强制Chrome正确渲染它:

function drag(ev) {
    ev.target.innerHTML += ' '; // Add space so that there is no kerning...
    ev.dataTransfer.setData("Text", ev.target.id);

    ev.dataTransfer.setDragImage(ev.target, ev.layerX - ev.target.offsetLeft, ev.layerY - ev.target.offsetTop);
}

It's working here http://jsfiddle.net/wv19zzsd/5/ 它在这里工作http://jsfiddle.net/wv19zzsd/5/

(In my fiddle I changed the Type to 'text/plain' only to test if that was the cause of the issue, but it is not) (在我的小提琴中,我将“类型”更改为“文本/纯文本”只是为了测试是否是问题的原因,但不是)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM