puppeteer/test/assets/input/drag-and-drop.html
Dan Park a91b8aca37 feat: add drag-and-drop support (#7150)
This commit adds drag-and-drop support, leveraging new additions to the CDP Input domain (Input.setInterceptDrags, Input.dispatchDragEvent, and Input.dragIntercepted).
2021-06-07 13:50:34 +02:00

47 lines
1.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Drag-and-drop test</title>
<style>
#drop {
width: 5em;
height: 5em;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="drag" draggable="true">drag me</div>
<div id="drop"></div>
<script>
window.didDragStart = false;
window.didDragEnter = false;
window.didDragOver = false;
window.didDrop = false;
var drag = document.getElementById('drag');
var drop = document.getElementById('drop');
drag.addEventListener('dragstart', function(e) {
e.dataTransfer.setData('id', e.target.id);
window.didDragStart = true;
});
drop.addEventListener('dragenter', function(e) {
e.preventDefault();
window.didDragEnter = true;
});
drop.addEventListener('dragover', function(e) {
e.preventDefault();
window.didDragOver = true;
});
drop.addEventListener('drop', function(e) {
e.preventDefault();
var id = e.dataTransfer.getData('id');
var el = document.getElementById(id);
if (el) {
e.target.appendChild(el);
window.didDrop = true;
}
});
</script>
</body>
</html>