最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论