我正在尝试在原生 HTML5 Drag And Drop API 中使用画布作为我的拖动图像。
问题是它适用于 Firefox,但不适用于 Chrome (58),我无法确定问题所在。
代码:https ://jsfiddle.net/196urLwd/5/
<div id="thing" draggable="true">DRAG ME</div>
function onDragStart(event){
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.width = 100;
canvas.height = 20;
context.fillStyle = '#333333';
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = '#999999';
context.font = 'bold 13px Arial';
context.fillText('DRAGGING...', 5, 15);
event.dataTransfer.setData('text', 'lorem ipsum');
event.dataTransfer.effectAllowed = 'copy';
event.dataTransfer.setDragImage(canvas, -15, 9);
};
var theThing = document.getElementById('thing');
theThing.addEventListener('dragstart', onDragStart, false);
我究竟做错了什么?