Paper.js画布由按钮触发的更改功能

时间:2014-04-22 07:38:03

标签: javascript html5 canvas paperjs

我正在尝试更新我的画布,通过按钮点击使用paper.js。为什么按钮不知道我的changePos()函数?

 <div class="myCanvas">
    <canvas id="canvas" width="600" height="600"></canvas>
  </div>

  <button id="some_button" onClick='changePos();'>Change Position</button>

在以下脚本中,第一个脚本是paper.js,第二个脚本在我的画布上初始化文本“hey”。这是changePos()函数所在的位置,在我看来,按钮应该在单击时调用。

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

<script  type="text/paperscript" canvas="canvas">

var text = new PointText({
      point: view.center,
      justification: 'center',
      fontSize: 20,
      fillColor: 'black'

    });

function init() {
  text.position = view.center;
      text.content = "hey"; 
}

function changePos() {
  text.content = "200";
}

init();
</script>

1 个答案:

答案 0 :(得分:1)

您可能会找到关于Paper.js Interoperability有用的答案。

为了能够从外部访问changePos(),您需要通过全局定义的对象导出它,例如全局或导出,然后在JavaScript中访问它。