我相信我有一个语法错误,但我已经尝试了一切,但无法解决这个问题。我正在使用Raphael Javascript矢量图形库,并试图从170,170到150,150绘制一条黑线,但没有显示任何内容。有谁能说出原因?
<html>
<head>
<script src="raphael.js"></script>
<script src="jquery-1.7.2.js"></script>
</head>
<body>
<div id="sample-2" style=" background-color:blue; width:500px;"></div>
<script type="text/javascript">
var paper = Raphael("sample-2", 900, 500);
//var curvePath = paper.path("M100,100 L400,400 C500,400 500,100 400,100");
//curvePath.attr({fill:"blue", stroke:"black"});
//var circle = paper.circle(175, 175, 50);
var newpath = paper.path({type:"path", path:"M170, 170 L150, 150", stroke:"black"});
//circle.attr({"fill": "orange"});
//circle.attr({"stroke": "black"});
</script>
</body>
</html>
答案 0 :(得分:2)
您滥用Paper.path()
构造函数。使用单个字符串参数调用它,表示路径字符串:
var newpath = paper.path("M170, 170 L150, 150");
如果您想更改路径的属性,例如笔触颜色,填充,字体使用attr()
方法,如下所示:
newpath.attr({
'stroke' : 'black',
'stroke-width' : 3
});
Raphaël参考: