snap.js/demos/animated-map/index.html

109 lines
3.9 KiB
HTML
Raw Normal View History

2013-09-06 04:09:36 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="copyright" content="Copyright © 2013 Adobe Systems Incorporated. All rights reserved.
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.">
<title>Long Flight</title>
2013-09-06 04:09:36 +00:00
<style media="screen">
body {
background: #2c4e6b;
}
</style>
2013-10-15 19:12:47 +00:00
<script src="../../dist/snap.svg-min.js"></script>
2013-09-06 04:09:36 +00:00
<script>
window.onload = function () {
1;
var g = Snap();
2013-09-06 04:09:36 +00:00
g.attr({
viewBox: [0, 0, 800, 600]
});
Snap.load("map.svg", function (f) {
2013-09-06 04:09:36 +00:00
function getShift(dot) {
return "t" + (400 - dot.x) + "," + (300 - dot.y);
}
var gr = f.select("g"),
wrd = f.select("#world").attr({fill: "#fff"}),
syd = f.select("#sydney").attr({fill: "red"}),
msk = f.select("#san_francisco").attr({fill: "red"}),
2013-09-06 04:09:36 +00:00
pth = f.select("#flight"),
pln = f.select("#plane"),
top = g.g();
top.attr({
mask: g.rect(100, 0, 600, 600).attr({
fill: "r(.5,.5,.25)#fff-#000"
})
});
var click = top.text(410, 310, "click!").attr({
font: "20px Source Sans Pro, sans-serif",
2013-09-06 04:09:36 +00:00
fill: "#fff"
});
pth.attr({
display: "none"
});
pln = gr.g(pln, pln.clone());
pln.attr({
display: "none"
});
pln[0].attr({
stroke: "#fff",
strokeWidth: 2
});
top.add(gr.attr({
transform: getShift({
x: syd.attr("cx"),
y: syd.attr("cy")
})
}));
var flight = gr.path().attr({
fill: "none",
stroke: "red",
strokeWidth: 3,
strokeDasharray: "5 3"
}).insertBefore(pln);
window.onclick = function () {
pln.attr({
display: ""
});
click.attr({
display: "none"
});
2013-10-16 06:51:56 +00:00
var flag,
len = pth.getTotalLength();
Snap.animate(0, len, function (l) {
flag = !flag;
// Safari bug workaround: forcing redraw
g.attr({width: 100 + (flag ? .00001 : 0) + "%"});
2013-09-06 04:09:36 +00:00
var dot = pth.getPointAtLength(l);
flight.attr({
d: pth.getSubpath(0, l)
});
pln.attr({
2013-10-16 06:51:56 +00:00
transform: "t" + [dot.x, dot.y] +
"r" + (dot.alpha - 90)
});
2013-09-06 04:09:36 +00:00
gr.attr({
transform: getShift(dot)
});
}, 10000);
};
});
};
</script>
</head>
<body>
</body>
</html>