0

我有个问题。我在画布中创建缩放图像,但我无法在 raphaeljs 中传输它如何放大光标坐标?

拉斐尔:http: //jsfiddle.net/qCzqF/2/

function zoomTo (x,y,z) {

c.translate(
    originx,
    originy
);
c.scale(z,z);
c.translate(
    -( x / scale + originx - x / ( scale * z ) ),
    -( y / scale + originy - y / ( scale * z ) )
);

originx = ( x / scale + originx - x / ( scale * z ) );
originy = ( y / scale + originy - y / ( scale * z ) );
scale *= z;

画布:http: //jsfiddle.net/JtctY/

function zoomTo (x,y,z) {

context.translate(
    originx,
    originy
);
context.scale(z,z);
context.translate(
    -( x / scale + originx - x / ( scale * z ) ),
    -( y / scale + originy - y / ( scale * z ) )
);

originx = ( x / scale + originx - x / ( scale * z ) );
originy = ( y / scale + originy - y / ( scale * z ) );
scale *= z;
4

1 回答 1

0

您的缩放功能对我来说似乎很好,您只是没有提供鼠标正确的 x/y 位置。您想使用相对于 svg 容器的鼠标位置

var mousex = event.clientX - paper.clientX;
var mousey = event.clientY - paper.clientY;

http://jsfiddle.net/mFaD2/

于 2013-05-07T12:13:01.317 回答