Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

1.1 KB
Raw Blame
<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>