2013-05-14 34 views
1

亲爱的我没有找到正常的解释,所以我决定寻求你的帮助。 我想在html文件中创建一个paper.js项目。我无法连接它们的问题我尝试使用var scope = new paper.PaperScope(); scope.setup(myCanvas);无法运行.html文件中的paper.js

但它没有解决。 这里是Paper.js web site

<!DOCTYPE html> 
<html> 
<head> 
<!-- Load the Paper.js library --> 
<script type="text/javascript" src="paper.js"></script> 
<!-- Define inlined JavaScript --> 
<script type="text/javascript"> 
    // Only executed our code once the DOM is ready. 
var scope = new paper.PaperScope(); 
scope.setup(myCanvas); 

var myPath = new Path(); 
myPath.strokeColor = 'black'; 

// This function is called whenever the user 
// clicks the mouse in the view: 
function onMouseDown(event) { 
    // Add a segment to the path at the position of the mouse: 
    myPath.add(event.point); 
} 
</script> 
</head> 
<body> 
    <canvas id="myCanvas" resize></canvas> 
</body> 
</html> 

采取的代码,但它不会在这里做什么... 感谢您的关注。

+0

我的猜测是,你不必在同一个文件夹中的文件'paper.js'作为你的html文件。 – Ryan 2013-05-14 16:51:55

+0

在JavaScript中编写时,所有内容都是纸张对象的属性 - >使用'new paper.Path()'而不是'New Path()' – jgillich 2013-05-14 17:01:44

+0

这两个文件都在同一个文件夹中,而且我使用过纸张。现在,仍然没有...但感谢您的建议 – Koranse 2013-05-14 17:21:40

回答

-1

你应该看看这个教程:http://paperjs.org/tutorials/getting-started/using-javascript-directly/

这里有一个工作示例:

<!DOCTYPE html> 
<html> 
<head> 
<!-- Load the Paper.js library --> 
<script type="text/javascript" src="paper.min.js"></script> 
<!-- Define inlined JavaScript --> 
    <script type="text/javascript"> 
     // Only executed our code once the DOM is ready. 
     window.onload = function() { 
      // Get a reference to the canvas object 
      var canvas = document.getElementById('myCanvas'); 
      // Create an empty project and a view for the canvas: 
      paper.setup(canvas); 

      var myPath = new paper.Path(); 
      myPath.strokeColor = 'black'; 

      // Draw the view now: 
      paper.view.draw(); 

      var tool = new paper.Tool(); 

      tool.onMouseDown = function(event) { 
       myPath.add(event.point); 
      } 
     } 
    </script> 
</head> 
<body> 
    <canvas id="myCanvas" resize></canvas> 
</body> 
</html> 
+0

噢男人:)该应用程序已准备好几个星期了:)但无论如何感谢。我明白 – Koranse 2013-07-17 22:26:35

+0

为什么downvote? – 2017-10-06 13:15:50