简体   繁体   English

paper.js处理程序不起作用

[英]paper.js handlers not working

I have a JavaScript file: 我有一个JavaScript文件:

    var canvas = document.createElement('canvas');
    canvas.id = 'canvas1';
    canvas.width = 400;
    canvas.height = 400;
    canvas.resize;

    var e = document.createElement('script');
    e.type = '/text/javascript/';
    e.src = '/static/notebook/js/paper.js';

    var c = document.createElement('script');
    c.type = '/text/javascript/';
    c.src = '/static/notebook/js/mypaper.js';

My mypaper.js file has the following function that is built into paper.js: 我的mypaper.js文件具有paper.js中内置的以下功能:

var d = document.getElementById('canvas1');
paper.setup(d);
function onFrame(event) {   //this function does not run 
console.log("test");        
}
var raster = new paper.Raster('/static/notebook/js/turtle.png'); //this works?

but it does not run. 但它无法运行。 I also noticed onkeydown does not work. 我还注意到onkeydown不起作用。 I believe this has something to do with the PaperScope but I am unsure. 我相信这与PaperScope有关,但是我不确定。 I can create rasters, paths and lines, they all display fine, except the functions don't run. 我可以创建栅格,路径和线,它们都可以正常显示,但功能无法运行。 I am trying to get it to animate in IPython Notebook. 我正在尝试使其在IPython Notebook中进行动画处理。

You could try to call call paper.js with 您可以尝试通过以下方式调用call paper.js

c.type="text/paperscript";

and see if this helps. 看看是否有帮助。 Or execute your code with PaperScript.execute(code, scope) 或者使用PaperScript.execute(代码,作用域)执行代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM