-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomDraggableExample01.htm
executable file
·48 lines (38 loc) · 1.74 KB
/
CustomDraggableExample01.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Custom Draggable Example</title>
<script src="EventUtil.js"></script>
</head>
<body>
<p>Try dragging the image over the square.</p>
<div style="width:80px;height:80px;background:url(smile.gif)" id="dragme" draggable="true"></div>
<div style="width: 100px; height: 100px; float: right; background: red" id="droptarget"></div>
<div id="output"></div>
<script>
var droptarget = document.getElementById("droptarget");
function handleEvent(event){
document.getElementById("output").innerHTML += event.type + "<br>";
if (event.type == "dropenter" || event.type == "dragover" || event.type=="drop"){
EventUtil.preventDefault(event);
}
}
EventUtil.addHandler(droptarget, "dragenter", handleEvent);
EventUtil.addHandler(droptarget, "dragover", handleEvent);
EventUtil.addHandler(droptarget, "dragleave", handleEvent);
EventUtil.addHandler(droptarget, "drop", handleEvent);
window.onload = function(){
var dragme = document.getElementById("dragme");
//backwards compatibility with IE < 10
if (!("draggable" in document.createElement("div")) && typeof dragme.dragDrop != "undefined"){
dragme.onmousedown = function(){
dragme.dragDrop();
};
}
EventUtil.addHandler(dragme, "dragstart", function(event){
event.dataTransfer.setData("Text", "Foo");
});
};
</script>
</body>
</html>