-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob5.html
102 lines (66 loc) · 2.5 KB
/
blob5.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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>blob5</title>
<script src="js/svg.js"></script>
<script src="js/svg.easing.min.js"></script>
<style type="text/css">
body {background:#333333;}
#logo {top:30px; left:30px; position:absolute; opacity:0.5;}
#drawing1 {width:100%; height:100%; }
#drawing1 svg {width:100%; height:100%; }
#shape1 {display:block; width:0; height:0;}
</style>
</head>
<body>
<object data="img/shape1.svg" type="image/svg+xml" id="shape1"></object>
<div id="logo"><a href="http://dlab.nyc/"><img src="img/dlab.svg" /></a></div>
<div id="drawing1"></div>
<script>
if (SVG.supported) {
var draw1 = SVG('drawing1');
draw1.attr("preserveAspectRatio", "xMidYMid").attr("viewBox", "0 0 792 612");
var group1 = draw1.group().attr('id', 'group1');
var group2 = draw1.group().attr('id', 'group2').move(200,0);
var path1 = draw1.path(/*'M150 0 L75 200 L225 200 Z'*/).fill('#000099').attr('id', 'pp1');
group1.add(path1).transform({ x: 30, y: 100 });
// reference external SVG and place into object
var p = document.getElementById("shape1");
// It's important to add a load event listener to the object,
// as it will load the svg doc asynchronously
p.addEventListener("load",function(){
// get the inner DOM of the svg
var svgDoc = p.contentDocument;
// get the inner element by id
var a = svgDoc.getElementById("path1");
var b = svgDoc.getElementById("path2");
// copy shape into other SVG
var svgA = SVG.adopt(a);
var svgB = SVG.adopt(b);
group1.add(svgA);
group2.add(svgB);
// reference path data in object B
c = svgA.array();
d = svgB.array();
// plot path data into object A
svgA.animate(1000).plot(d);
// add behavior
a.addEventListener("mousedown",function(){
shapeShift(svgB,c);
}, false);
}, false);
function shapeCopy(object,path) {
console.log("shapeCopy: " + path);
//object.adopt(path);
}
function shapeShift(object,path) {
console.log("shapeShift: " + object);
console.log("shapeShift: " + path);
object.animate(2000).plot(path);
}
} else {
alert('SVG not supported')
}
</script>
</body>
</html>