1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width">
<head>
<style>
body {
width: 100%;
height: 100%;
margin: 0;
}
img {
width: 100px;
height: 100px;
}
#target1 {
left: 0;
top: 200px;
}
#target2 {
left: 200px;
top: 0;
}
#target3 {
left: 200px;
top: 200px;
}
.target {
position: absolute;
background-color: red;
border-radius: 50%;
width: 100px;
height: 100px;
color: white;
text-align: center;
line-height: 90px;
}
#description {
padding-top: 250px;
display: block;
}
#container {
position: relative;
}
</style>
</head>
<body>
<div id="container">
<img src="apple.gif"></img>
<div id="target1" class="target"></div>
<div id="target2" class="target"></div>
<div id="target3" class="target"></div>
<code id="description">
<div>To test this manually, drag the image onto each of the three red circles.</div>
<div>Each red circle should turn green upon dragging over it.</div>
<div>Upon drop, the text "PASS" should appear in each target.</div>
</code>
</div>
</body>
<script>
function elementAtMouseEvent(e) {
if (window.usePageCoordinates)
return document.elementFromPoint(e.pageX - pageXOffset, e.pageY - pageYOffset);
return document.elementFromPoint(e.clientX, e.clientY);
}
function targetAtEvent(e) {
let target = elementAtMouseEvent(e);
return target && target.classList.contains("target") ? target : null;
}
function resetTestState() {
target1.style.backgroundColor = "";
target2.style.backgroundColor = "";
target3.style.backgroundColor = "";
target1.innerHTML = "";
target2.innerHTML = "";
target3.innerHTML = "";
}
document.body.addEventListener("dragstart", resetTestState);
document.body.addEventListener("dragenter", event => {
let target = targetAtEvent(event);
if (target)
target.style.backgroundColor = "green";
event.preventDefault();
});
document.body.addEventListener("dragover", event => {
let target = targetAtEvent(event);
if (target)
target.style.backgroundColor = "green";
event.preventDefault();
});
document.body.addEventListener("drop", event => {
let target = targetAtEvent(event);
if (target)
target.innerHTML = `<code>PASS</code>`;
event.preventDefault();
});
</script>
</html>
|