其他答案是正确的——你想使用 setViewBox。
这是一个支持动画的版本。它并不完全漂亮,您必须查看页面源代码才能提取代码,但它应该或多或少完全符合您的要求。
这是作为 Raphael 扩展的视图框动画:
Raphael.fn.animateViewBox = function animateViewBox( x, y, w, h, duration, easing_function, callback )
{
var cx = this._viewBox ? this._viewBox[0] : 0,
dx = x - cx,
cy = this._viewBox ? this._viewBox[1] : 0,
dy = y - cy,
cw = this._viewBox ? this._viewBox[2] : this.width,
dw = w - cw,
ch = this._viewBox ? this._viewBox[3] : this.height,
dh = h - ch,
self = this;;
easing_function = easing_function || "linear";
var interval = 25;
var steps = duration / interval;
var current_step = 0;
var easing_formula = Raphael.easing_formulas[easing_function];
var intervalID = setInterval( function()
{
var ratio = current_step / steps;
self.setViewBox( cx + dx * easing_formula( ratio ),
cy + dy * easing_formula( ratio ),
cw + dw * easing_formula( ratio ),
ch + dh * easing_formula( ratio ), false );
if ( current_step++ >= steps )
{
clearInterval( intervalID );
callback && callback();
}
}, interval );
}
(不是那么漂亮)演示在这里:http: //voidblossom.com/tests/easedViewBox.php
如果您真的很想使用变换(如果利用得当,它可能会带来一些好处,但与视图框操作相比通常会很脆弱),还有另一个使用变换的示例,位于http://voidblossom.com/tests/zoomByTransform .php _