我在HTML文件中有以下内容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='test.js'></script>
</head>
<body>
<svg width='570' height='500' style='border: 2px solid #000;'>
<rect id='test-rect' class='a-rect' draggable='true'
stroke-width='1' stroke='#000' fill='#fff'
ry='10' rx='10' r='10'
height='119' width='168' y='169' x='282'>
</rect>
</svg>
</body>
</html>
以及test.js
document.addEventListener('DOMContentLoaded', function () {
var elem = document.getElementById('test-rect');
elem.addEventListener('mousedown', function (event) {
console.log('You mouse-downed on a \' SVG node!', event);
});
elem.addEventListener('dragstart', function (event) {
event.dataTransfer.effectAllowed = 'all';
event.dataTransfer.setData('text/html', 'node');
console.log('And now you\'re DRAGGIN\' a SVG node!', event);
});
elem.addEventListener('drag', function (event) {
console.log('Still doin\' it!', event);
});
elem.addEventListener('dragend', function (event) {
console.log('Done!', event);
});
});
mousedown
和dragstart
事件正在正常启动,但drag
和dragend
都没有做同样的事情。我从大约一年前读过this question表示我必须致电setData
才能drag
开火,但是没有这样做。
如何在Firefox中的SVG节点上获取正确的HTML5 drag
,更重要的是,dragend
事件触发?