paper.js代码没有运行

时间:2016-10-08 09:15:22

标签: javascript paperjs

我最近开始使用Paper.js。试图直接使用javascript我无法弄清楚为什么下面的代码在运行时绝对没有产生:

  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>paper1</title>

<script type="text/javascript" src="js/paper.js"></script>
<script type="text/javascript"> 

    window.onload = function() {

    var canvas = document.getElementById("myCanvas");
    paper.setup(canvas);

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

    var tool = new paper.Tool();

     tool.onMouseDown = function(event) {
           path.add(event.point);               
            }

    paper.view.draw();
    };

</script>

</head>
<body>
<canvas id="myCanvas" resize></canvas>

</body>

我很感激任何想法

更新
它删除window.onload时有效。为什么会这样?

1 个答案:

答案 0 :(得分:0)

Actually, something does show up. Try to click on the uper left most area of the canvas and the lines will show up. But if you click more on the bottom right, you will see that the lines are not added were you click but are shifted.

There seems to be a problem when using the resize attribute. Remove it and add the dimensions manually and it will work as inteded:

<canvas id="myCanvas" width="500" height="300"></canvas>