2011-01-11 105 views
1

我有一个演示使用raphael.js。它的代码非常简单,但在Internet Explorer中查看(少于第9版)时,我得到一张1000px×1000px的Raphael画布,我无法弄清楚原因。我正在使用Raphael的1.5.2版本。下面的代码:Raphael.JS为什么创建尺寸为1000x1000的纸张?

HTML

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="UTF-8"> 
    <title>Raphael Test</title> 
    <link rel="stylesheet" type="text/css" href="test.css"> 
    <link href="../shared/img/favicon.png" rel="shortcut icon"> 
    </head> 
    <body> 
    <div id="graph"></div> 
    <script src="../shared/js/raphael/raphael-min.js" type="text/javascript"> </script> 
    <script src="test.js" type="text/javascript"> </script> 
    </body> 
</html> 

CSS

/* Graph */ 
#graph { padding: 5px; width: 477px; height: 299; } 

JS

var holder = document.getElementById('graph') 
    , width = holder.scrollWidth 
    , height = Math.round(width * 0.5625) + 25 
    , p = Raphael(10, 50, width, height) 
    , c = p.circle(p.width - 50, p.height - 50, 50); 
alert(p.width + ' & ' + p.height); 

我发现了一个讨论Raphael's Google group与同样的问题,但没有解决。

+2

您确定要访问`p.width`(width属性),而不是`p.style.width`吗? – user123444555621 2011-01-11 02:32:46

回答

1

我有同样的问题,并使用

var width = paper.canvas.clientWidth ? paper.canvas.clientWidth : paper.width; 
var height = paper.canvas.clientHeight ? paper.canvas.clientHeight : paper.height; 

代替paper.width和paper.height解决它即比9版本和所有其他浏览器更旧。

相关问题