Skip to content

Commit

Permalink
feat: add a draggable element test page
Browse files Browse the repository at this point in the history
  • Loading branch information
dbushong committed Apr 18, 2016
1 parent 5f043f2 commit 8252fd6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ This page contains `div#nested-frame-div`.
#### `/popup.html`

Can be opened by clicking on `button#open-popup` and contains `div.popup-only`.

#### `/draggable.html`

Displays a draggable element for testing buttonDown/Up and movePointer...
42 changes: 42 additions & 0 deletions public/draggable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<body>
<style>
body { height: 600px; }
#box {
position: fixed;
left: 0;
top: 0;
width: 100px;
height: 100px;
border: 1px solid black;
}
</style>
<div id=box>whee</div>
<script>
var startMouse
, startBox
, body = document.body
, box = document.getElementById('box');
function mouseDown(ev) {
startMouse = [ev.clientX, ev.clientY];
startBox = box.getBoundingClientRect();
body.addEventListener('mouseup', mouseUp, false);
body.addEventListener('mousemove', mouseMove, false);
ev.preventDefault(); return false;
}
function mouseMove(ev) {
var dx = ev.clientX - startMouse[0]
, dy = ev.clientY - startMouse[1];
box.style.left = startBox.left + dx + 'px';
box.style.top = startBox.top + dy + 'px';
}
function mouseUp(ev) {
body.removeEventListener('mouseup', mouseUp);
body.removeEventListener('mousemove', mouseMove);
ev.preventDefault(); return false;
}
window.addEventListener('load', function () {
box.addEventListener('mousedown', mouseDown, false);
});
</script>
</body>

0 comments on commit 8252fd6

Please sign in to comment.