This repository has been archived by the owner on Sep 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultitouch Drag.html
77 lines (62 loc) · 1.52 KB
/
Multitouch Drag.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
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<style>
html,
body {
height: 100%;
margin: 0;
overflow: hidden;
}
svg {
position: absolute;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = self.frameElement ? 960 : innerWidth,
height = self.frameElement ? 500 : innerHeight;
var data = d3.range(20).map(function() { return [Math.random() * width, Math.random() * height]; });
var color = d3.scale.category10();
var drag = d3.behavior.drag()
.origin(function(d) { return {x: d[0], y: d[1]}; })
.on("dragstart", dragstarted)
.on("drag", dragged)
.on("dragend", dragended);
d3.select("body")
.on("touchstart", nozoom)
.on("touchmove", nozoom)
.append("svg")
.attr("width", width)
.attr("height", height)
.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("transform", function(d) { return "translate(" + d + ")"; })
.attr("r", 32)
.style("fill", function(d, i) { return color(i); })
.call(drag);
function dragstarted() {
this.parentNode.appendChild(this);
d3.select(this).transition()
.ease("elastic")
.duration(500)
.attr("r", 48);
}
function dragged(d) {
d[0] = d3.event.x;
d[1] = d3.event.y;
d3.select(this)
.attr("transform", "translate(" + d + ")");
}
function dragended() {
d3.select(this).transition()
.ease("elastic")
.duration(500)
.attr("r", 32);
}
function nozoom() {
d3.event.preventDefault();
}
</script>