我目前使用velocity.js来控制我创建的SVG绘图上的一些动画。它与用户互动,所以当某些部分发生点击时,图片可能会向右或向下扩展。到目前为止,一切工作都很完美,直到SVG盒子的图片太大。Animate SVG视图框更改
在这些情况下,我只是调整视图的大小来缩放图像。
svgDoc.setAttribute("viewBox", "0 0 " + svgDocWidth + " " + svgDocHeight);
这工作,但因为它不是动画它看起来并不大。它只是跳到新的尺寸。有没有办法使用velocity.js进行动画效果viewBox更改?
我试过这种方法:
$viewBox = $(svgDoc.viewBox);
$viewBox.velocity({height: svgDocHeight, width: svgDocWidth});
但是,这并不做任何事情。
这超出了velocity.js能支持的范围吗?在2015年11月21日
@Ian
解决方案给了我最终使用的解决方案。它结束了看起来像这样:
var origHeight = this.svgDoc.viewBox.animVal.height;
var origWidth = this.svgDoc.viewBox.animVal.width;
var docHeight = this.SvgHeight();
var docWidth = this.SvgWidth();
if ((origHeight != docHeight) || (origWidth != docWidth))
{
var deltaHeight = docHeight - origHeight;
var deltaWidth = docWidth - origWidth;
$(this.svgDoc).velocity(
{
tween: 1
},
{
progress: function(elements, complete, remaining, start, tweenValue)
{
var newWidth = origWidth + complete * deltaWidth;
var newHeight = origHeight + complete * deltaHeight;
elements[0].setAttribute('viewBox', '0 0 ' + newWidth + ' ' + newHeight);
}
});
}
有库/如果Chrome删除它,则会添加SMIL的polyfills。 –