-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path拖拽-div.html
45 lines (45 loc) · 1.09 KB
/
拖拽-div.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
#r {
width: 100px;
height: 100px;
border: 1px solid #eee;
background-color: aqua;
cursor: pointer;
position: relative;
}
</style>
</head>
<body>
<div id="r"></div>
<script>
var drag = d3.behavior.drag()
.on('dragstart', function() {
console.log(d3.event);
react.style({'background': 'red'})
})
.on('drag', function(){
console.log(d3.event);
react.style({
'left': (d3.event.x-25)+'px',
'top':(d3.event.y-25)+'px',
'background':'green'
});
})
.on('dragend', function(){
console.log(d3.event);
react.style({'background':'#000'});
});
var react = d3.select('#r')
.style({'left':'50px','top':'50px'})
.call(drag);
</script>
</body>
</html>