首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从.html文件运行paper.js

无法从.html文件运行paper.js
EN

Stack Overflow用户
提问于 2013-05-14 23:58:24
回答 1查看 4.2K关注 0票数 1

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

但这并没有起作用。下面是摘自Paper.js web site的代码

代码语言:javascript
复制
    <!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>

但它在这里什么也做不了..。感谢您的关注。

EN

回答 1

Stack Overflow用户

发布于 2013-07-17 06:06:35

您应该看看本教程:http://paperjs.org/tutorials/getting-started/using-javascript-directly/

下面是一个有效的示例:

代码语言:javascript
复制
<!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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16547738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档