我设法通过一些技巧对raphael画布进行缩放,因为设置视图框(setviewbox)对我来说不起作用,这是我编写的函数:
function setCTM(element, matrix) {
var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
element.setAttribute("transform", s);
}
Raphael.fn.zoomAndMove = function(coordx,coordy,zoom) {
var svg = document.getElementsByTagName("svg")[0];
var z = zoom;
var g = document.getElementById("viewport1");
var p = svg.createSVGPoint();
p.x = coordx;
p.y = coordy;
p = p.matrixTransform(g.getCTM().inverse());
var k = svg.createSVGMatrix().scale(z).translate(-p.x, -p.y);
setCTM(g, g.getCTM().multiply(k));
}
其中视口元素1的定义为:
var gelem = document.createElementNS('http://www.w3.org/2000/svg', 'g');
gelem.id = 'viewport1';
paper.canvas.appendChild(gelem);
paper.canvas = gelem;
那么我可以调用:paper.zoomAndMove(minx,miny,zoomRatio);
有没有可能改变这个函数使其平滑缩放?