mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
a91b8aca37
This commit adds drag-and-drop support, leveraging new additions to the CDP Input domain (Input.setInterceptDrags, Input.dispatchDragEvent, and Input.dragIntercepted).
47 lines
1.2 KiB
HTML
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>
|