【发布时间】:2016-05-03 15:51:29
【问题描述】:
下面的 plunker 用美国的 SVG 地图显示了我的粗略动画。
https://plnkr.co/edit/gXWTk1fGeVUOQJM52OPs?p=preview
<svg id="svg" width="100%" height="100%" viewBox="0 0 959 593"></svg>
JS:
var states = s.selectAll('.state');
states.forEach(function(element) {
element.click(function(){
this.attr({
fill: 'red'
});
if (!this.isTransformed) {
svg.animate({
transform: 's10'
});
this.animate({
// the transform
transform: 'R 360 S 3 T0, 0',
}, 750, mina.easeout);
this.transform('T0,0');
this.isTransformed = true;
activeRegion = this.node.id;
states.forEach(function(element) {
if (element.node.id !== activeRegion) {
element.addClass('ng-hide');
}
});
} else {
states.forEach(function(element) {
element.removeClass('ng-hide');
});
this.animate({
transform: 'R 0 S 1',
fill: '#E0E0E0'
}, 750, mina.easeout);
this.isTransformed = false;
}
});
element.mouseover(function(){
this.attr({fill: "yellow"});
});
element.mouseout(function(){
this.attr({fill: "#E0E0E0"});
});
});
这个 plunker 使用 Snap.svg 加载现有的 SVG。
当您单击各个状态时,会出现一个粗略的动画。地图外边缘的状态并不完全可见。
我想知道如何transform所有状态到论文的中心?
【问题讨论】:
标签: javascript svg raphael snap.svg