-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdragndrop.html
More file actions
57 lines (46 loc) · 1.32 KB
/
dragndrop.html
File metadata and controls
57 lines (46 loc) · 1.32 KB
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
<!DOCTYPE html>
<html>
<head>
<style>
img { position: absolute; }
</style>
<script>
window.onload = function() {
movMeId = document.getElementById("ImgMov");
movMeId.style.top = "80px";
movMeId.style.left = "80px";
document.onmousedown = coordinates;
document.onmouseup = mouseup;
function coordinates(e) {
if (e == null) { e = window.event;}
// e.srcElement holds the target element in IE, whereas e.target holds the target element in Firefox
// Both properties return the HTML element the event took place on.
var sender = (typeof( window.event ) != "undefined" ) ? e.srcElement : e.target;
if (sender.id=="ImgMov") {
mouseover = true;
pleft = parseInt(movMeId.style.left);
ptop = parseInt(movMeId.style.top);
xcoor = e.clientX;
ycoor = e.clientY;
document.onmousemove = moveImage;
return false;
}
return false;
}
function moveImage(e) {
if (e == null) { e = window.event; }
movMeId.style.left = pleft+e.clientX-xcoor+"px";
movMeId.style.top = ptop+e.clientY-ycoor+"px";
return false;
}
function mouseup(e) {
document.onmousemove = null;
}
}
</script>
</head>
<body>
<img id="ImgMov" src="http://placehold.it/100x100&text=JS" width="64" height="64">
<p>Drag and drop around the image in this page.</p>
</body>
</html>