admin管理员组文章数量:1302379
I have defined my raphael paper like below:
var paper = Raphael("my-paper", '100%', '100%');
//render some shapes on my paper
var e = paper.ellipse(50, 50, 40, 20);
var c = paper.circle(50, 50, 40);
var r = paper.rect(40, 40, 50, 50, 10);
As you saw above, I defined my Raphael paper, then drew some shapes on my paper. I have following two questions to ask:
1. How to get the center point x and y value of my paper. (x: horizontal location, y: vertical location)
2. I would like to scale everything on my paper to twice bigger size, I know I can use Raphel scale function. I would like to scale all the elements on the paper relative to the center of my paper, so, I need to do something like:
e.scale(2, 2, CENTER_X, CENTER_Y)
( CENTER_X
and CENTER_Y
are asked in question 1 )
I'd like the result looks like zoom in, am I using in the right way or are there other ways to do it?
I have defined my raphael paper like below:
var paper = Raphael("my-paper", '100%', '100%');
//render some shapes on my paper
var e = paper.ellipse(50, 50, 40, 20);
var c = paper.circle(50, 50, 40);
var r = paper.rect(40, 40, 50, 50, 10);
As you saw above, I defined my Raphael paper, then drew some shapes on my paper. I have following two questions to ask:
1. How to get the center point x and y value of my paper. (x: horizontal location, y: vertical location)
2. I would like to scale everything on my paper to twice bigger size, I know I can use Raphel scale function. I would like to scale all the elements on the paper relative to the center of my paper, so, I need to do something like:
e.scale(2, 2, CENTER_X, CENTER_Y)
( CENTER_X
and CENTER_Y
are asked in question 1 )
I'd like the result looks like zoom in, am I using in the right way or are there other ways to do it?
Share Improve this question asked Jun 7, 2011 at 14:07 LeemLeem 18.3k39 gold badges112 silver badges164 bronze badges 1- Are you still looking for this answer? I can provide you with a working example... – ffleandro Commented Jul 10, 2012 at 14:05
2 Answers
Reset to default 8paper.width and paper.height should return the dimensions of the paper which would give you the center.
You can find center of the paper like this
var x = this.paper.canvas.offsetLeft;
var y = this.paper.canvas.offsetTop;
var centerX = x + paper.width/2 ;
var centerY= y + paper.height/2;
本文标签:
版权声明:本文标题:javascript - Raphael.js How to get center point location of paper and scale relative to the center? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741698840a2393169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论