forked from hueitan/snap.svg.zpd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
195 lines (173 loc) · 7.23 KB
/
index.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>A zoom/pan/drag/rotate plugin for Snap.svg</title>
<style>
html, body { margin:0; padding:0; overflow:hidden }
svg { position:fixed; top:0; left:0; height:100%; width:100% }
.dragText {
font-size: 100px;
}
.button {
position: fixed;
right: 50px;
bottom: 50px;
z-index: 100;
}
</style>
<script src="./lib/snap.svg.js"></script>
<script src="./snap.svg.zpd.js"></script>
</head>
<body>
<div class="button">
<button id="location">To (0,0) Location</button>
<br/>
<button id="up">Up</button>
<button id="down">Down</button>
<br/>
<button id="left">Left</button>
<button id="right">Right</button>
<br/>
<button id="rotateL">Rotate -15 deg</button>
<button id="rotateR">Rotate 15 deg</button>
<br/>
<button id="zoom2x">Zoom To 2x</button>
<button id="zoom1x">Zoom To 1x</button>
<br/>
<button id="save">Save</button>
<button id="threshold">Zoom Threshold [0.5,3]</button>
<br/>
<button id="destroy">Destroy</button>
<button id="reapply">Re-Apply</button>
<br/>
-- or use arrow key --
</div>
<script>
var paper = Snap();
var image1 = paper.image('./lib/image1.png',820,270);
var image2 = paper.image('./lib/image2.png',100,220, 500,205);
var image3 = paper.image('./lib/image3.png',500,100, 400,332.5);
var text = paper.text(50, 100, 'drag me').addClass('dragText');
/*
Snap.load('http://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg', function (data) {
var s = document.createElementNS('http://www.w3.org/2000/svg', 'g');
s.appendChild(data.node);
paper.append(s);
paper.zpd();
});
*/
var applyZpd = function() {
paper.zpd({ drag: true });
};
// run initializer
applyZpd();
// UI improvement needed
var intervalF;
var clearIntervalF = function () {
clearInterval(intervalF);
}
document.getElementById('location').onmousedown = function () {
paper.panTo(0, 0);
};
document.getElementById('left').onmousedown = function () {
paper.panTo('-10');
intervalF = setInterval(function () {
paper.panTo('-10');
}, 100);
};
document.getElementById('left').onmouseup = clearIntervalF;
document.getElementById('left').onmouseleave = clearIntervalF;
document.getElementById('right').onmousedown = function () {
paper.panTo('+10');
intervalF = setInterval(function () {
paper.panTo('+10');
}, 100);
};
document.getElementById('right').onmouseup = clearIntervalF;
document.getElementById('right').onmouseleave = clearIntervalF;
document.getElementById('up').onmousedown = function () {
paper.panTo('+0', '-10');
intervalF = setInterval(function () {
paper.panTo('+0', '-10');
}, 100);
};
document.getElementById('up').onmouseup = clearIntervalF;
document.getElementById('up').onmouseleave = clearIntervalF;
document.getElementById('down').onmousedown = function () {
paper.panTo('+0', '+10');
intervalF = setInterval(function () {
paper.panTo('+0', '+10');
}, 100);
};
document.getElementById('down').onmouseup = clearIntervalF;
document.getElementById('down').onmouseleave = clearIntervalF;
document.getElementById('rotateL').onmousedown = function () {
paper.rotate(-15);
intervalF = setInterval(function () {
paper.rotate(-15);
}, 100);
};
document.getElementById('rotateL').onmouseup = clearIntervalF;
document.getElementById('rotateL').onmouseleave = clearIntervalF;
document.getElementById('rotateR').onmousedown = function () {
paper.rotate(15);
intervalF = setInterval(function () {
paper.rotate(15);
}, 100);
};
document.getElementById('rotateR').onmouseup = clearIntervalF;
document.getElementById('rotateR').onmouseleave = clearIntervalF;
document.getElementById('zoom2x').onmousedown = function () {
paper.zoomTo(2, 400);
};
document.getElementById('zoom1x').onmousedown = function () {
paper.zoomTo(1, 400);
};
document.getElementById('save').onmousedown = function () {
paper.zpd('save', function (err, data) {
var output = JSON.stringify(data);
alert('Save Data:' + output);
});
};
document.getElementById('threshold').onmousedown = function () {
paper.zoomTo(1, 400);
paper.zpd({ drag: true, zoomThreshold: [0.5, 3] });
};
document.onkeydown = function (e) {
switch(e.keyCode) {
case 37: // left
paper.panTo('-10');
break;
case 38: // up
paper.panTo('+0', '-10');
break;
case 39: // right
paper.panTo('+10');
break;
case 40: // down
paper.panTo('+0', '+10');
break;
}
};
document.getElementById('destroy').onmousedown = function () {
paper.zpd('destroy');
};
document.getElementById('reapply').onmousedown = function () {
applyZpd();
};
// settings
// paper.zpd({ zoom: true, pan: true, drag: true, zoomScale: 0.2 });
// paper.zpd(function (err, paper) { console.log(paper); });
// paper.zpd({ zoom: false }, function (err, paper) { console.log(paper); });
// zoomTo
// paper.zoomTo(1.5, 1000, mina.bounce, function (err, paper) { console.log(paper); });
// destroy
// paper.zpd('destroy');
// load
// paper.zpd({ load: {a:0.6787972450256348,b:0,c:0,d:0.6787972450256348,e:159.63783264160156,f:12.84811782836914}});
</script>
</body>
</html>