我有一个被拖放到SVG画布上的单位列表。你可以看到它,这里。
为此操作定义和配置单元的方式如下:
var units = html.document.querySelectorAll('ul.units li');
units.onDragStart.listen(_onDragStart);
units.onDragEnd.listen(_onDragEnd);
void _onDragStart(html.MouseEvent e) {
_dragSource = e.target as html.LIElement;
_dragSource.classes.add('moving');
e.dataTransfer.effectAllowed = 'move';
if (isFirefox) {
e.dataTransfer.setData('text/plain', 'Required for Firefox!');
}
}
void _onDragEnd(html.MouseEvent e) {
_dragSource.classes.remove('moving');
}SVG画布有以下定义:
canvas = html.document.querySelector(canvas_id);
canvas.onDragOver.listen(_onDragOver);
canvas.onDrop.listen(_onDrop);
void _onDragOver(html.MouseEvent e) {
e.preventDefault();
}
void _onDrop(html.MouseEvent e) {
e.preventDefault();
html.Element dropTarget = e.target;
if (dropTarget == canvas && _dragSource != null && _dragSource.classes.contains('moving')) {
String operatorId = 'operator_${opNumber}';
var mouseCoordinates = getRelativeMouseCoordinates(e);
operators[operatorId] = addOperator(operatorId, _dragSource.dataset['unit-type'], mouseCoordinates['x'], mouseCoordinates['y']);
opNumber += 1;
}
}除了Windows上的IE和Safari之外,这对所有浏览器都有效。问题是我甚至没有收到任何错误或异常消息。你们有什么想法吗?
发布于 2014-03-05 01:25:44
IE11和更早版本不支持SVG元素的HTML5拖放。我制作了一个简单的科德芬,您可以使用它在不同的浏览器上进行测试。
如果要支持SVG元素上的拖放,则需要进行手动命中测试。如果你感兴趣,你可以看看drag-drop.dart。这是我的一个库,支持跨浏览器拖放SVG。文档是不存在的,但是您可以查看示例和测试来了解如何使用它。
发布于 2014-03-07 01:08:05
https://stackoverflow.com/questions/22180314
复制相似问题