playwright/tests/assets/drag-n-drop.html
Dmitry Gozman 06e0ea5e24
test: unflake page-drag tests (#17783)
To avoid rounding errors, make coordinates even.
2022-10-03 12:26:36 -07:00

58 lines
1.1 KiB
HTML

<style>
* {
box-sizing: border-box;
}
body, html {
margin: 0;
padding: 0;
}
div:not(.mouse-helper) {
margin: 0;
padding: 0;
}
#source {
color: blue;
border: 1px solid black;
position: absolute;
left: 20px;
top: 20px;
width: 200px;
height: 100px;
}
#target {
border: 1px solid black;
position: absolute;
left: 40px;
top: 200px;
width: 400px;
height: 300px;
}
</style>
<script>
function dragstart_handler(ev) {
ev.currentTarget.style.border = "dashed";
ev.dataTransfer.setData("text/plain", ev.target.id);
}
function dragover_handler(ev) {
ev.preventDefault();
}
function drop_handler(ev) {
console.log("Drop");
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
<body>
<div>
<p id="source" ondragstart="dragstart_handler(event);" draggable="true">
Select this element, drag it to the Drop Zone and then release the selection to move the element.</p>
</div>
<div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);">Drop Zone</div>
</body>