-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragTest.html
120 lines (112 loc) · 2.87 KB
/
dragTest.html
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
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
#divObj{width:90px;height:90px;position:absolute;background:purple;line-height:90px;text-align:center;font-size:15px;color:#fff;z-index:10}
canvas{position:absolute;left:150px}
</style>
</head>
<body>
<div id="divObj">
Drag me!!
</div>
<canvas id="canvas3" width="150" height="150"></canvas>
<script type="text/javascript">
var v_data ={
canvas : document.getElementById("canvas3"),
ctx : document.getElementById("canvas3").getContext("2d"),
dataList : [10, 45, 55],
colorList : ['yellow', 'red', 'blue'],
pie: function() {
var radius = v_data.canvas.height / 2 - 5;
var centerX = v_data.canvas.width / 2;
var centerY = v_data.canvas.height / 2;
var total = 0;
for(i=0; i < v_data.dataList.length; i++) {
total += v_data.dataList[i];
};
var lastend=0;
var offset = Math.PI / 2;
for(i=0; i < v_data.dataList.length; i++) {
var thispart = v_data.dataList[i];
v_data.ctx.beginPath();
v_data.ctx.fillStyle = v_data.colorList[i];
v_data.ctx.moveTo(centerX,centerY);
var arcsector = Math.PI * (2 * thispart / total);
v_data.ctx.arc(centerX, centerY, radius, lastend - offset, lastend + arcsector - offset, false);
v_data.ctx.lineTo(centerX, centerY);
v_data.ctx.fill();
v_data.ctx.closePath();
lastend += arcsector;
}
}
}
v_data.pie()
var m3 = {
dragStart : function(event){
var doc = document;
var domObj = doc.getElementById("divObj");
domObj.onmousedown = function(event){
var startX = event.clientX, startY = event.clientY;
var objX = domObj.offsetLeft, objY = domObj.offsetTop;
var calX = startX - objX, calY = startY - objY;
if (doc.addEventListener) {
doc.addEventListener("mousemove",dragMove,true);
doc.addEventListener("mouseup",dragEnd,true);
}
else {
domObj.setCapture();
domObj.attachEvent("onmousemove",dragMove);
domObj.attachEvent("onmouseup",dragEnd);
}
if (event.stopPropagation) {
event.stopPropagation();
}
else {
event.cancelBubble = true;
}
event.preventDefault();
function dragMove(e) {
if (!e) e = event
domObj.style.left = e.clientX - calX + "px";
domObj.style.top = e.clientY - calY + "px";
if (e.stopPropagation) {
e.stopPropagation()
}
else {
e.cancelBubble = true
}
}
function dragEnd(e) {
if (doc.removeEventListener) {
doc.removeEventListener("mouseup",dragEnd,true);
doc.removeEventListener("mousemove",dragMove,true);
}
else {
domObj.detachEvent("onmouseup",dragEnd)
domObj.detachEvent("onmousemove",dragMove);
domObj.releaseCapture()
}
if (e.stopPropagation) {
e.stopPropagation()
}
else {
e.cancelBubble = true
}
}
}
},
init : function() {
m3.dragStart()
}
}
var nameV = {
map : "map",
me : "me",
main : "main"
}
m3.init()
</script>
</body>
</html>