How to get the width of the paper canvas of the Raphael javascript library, which is defined with relative values? - Stack Overf

I am playing with the Raphael SVG library and I defined aelement holding the Raphael canvas<div id

I am playing with the Raphael SVG library and I defined a element holding the Raphael canvas

<div id="canvas_container"></div>

and I placed the Raphael canvas/paper inside it :

paper = new Raphael(document.getElementById('canvas_container'), '100%', '100%');

Now I would like to get the absolute width/height of the canvas. I figured out how to access the canvas with paper.canvas but if I try to get the paper.canvas.width I get a SVGAnimatedLength element and not the width.

I noticed when using the Chrome dev-tools and selecting the paper.canvas in the console with the mouse, the proper absolute size appears in the window by the selected element (the blue selection appearing in the page when some element selected in the Chrome dev console). But how to get it in the code ?

I am playing with the Raphael SVG library and I defined a element holding the Raphael canvas

<div id="canvas_container"></div>

and I placed the Raphael canvas/paper inside it :

paper = new Raphael(document.getElementById('canvas_container'), '100%', '100%');

Now I would like to get the absolute width/height of the canvas. I figured out how to access the canvas with paper.canvas but if I try to get the paper.canvas.width I get a SVGAnimatedLength element and not the width.

I noticed when using the Chrome dev-tools and selecting the paper.canvas in the console with the mouse, the proper absolute size appears in the window by the selected element (the blue selection appearing in the page when some element selected in the Chrome dev console). But how to get it in the code ?

Share Improve this question edited Oct 3, 2019 at 7:43 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Mar 4, 2013 at 14:50 karlitoskarlitos 1,6564 gold badges29 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You can use the offsetWidth and offsetHeight values of the canvas object in order to determine the true dimensions of the Raphael canvas.

Example: http://jsfiddle/g54PR/1/

The properties paper.width and paper.hight will help you.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744544781a4579945.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信