我试图在生活中运行p5,但是得到了这个错误:
未定义的TypeError:无法读取未定义的属性“className”
没有生命它就不会出现。
sketch.js
var sketch = (function(p5) {
setup = function() {
p5.createCanvas(p5.windowWidth, p5.windowHeight);
p5.background(0);
};
}(new p5(sketch, "canvas")));index.html
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.23/p5.js"></script>
</head>
<body>
<script language="javascript" type="text/javascript" src="main.js"></script>
<div id = "canvas"></div>
</body>
</html>发布于 2017-04-30 18:11:12
你的语法有点奇怪。为什么要在括号中同时包装函数和对new p5()的调用?此外,您还缺少了setup()函数定义的变量名。
纠正所有这些都是这样的:
var sketch = function(p5) {
p5.setup = function() {
p5.createCanvas(p5.windowWidth, p5.windowHeight);
p5.background(0);
};
}
new p5(sketch, "canvas");我也不会使用p5作为变量或参数名,因为这是整个p5.js库的名称,所以我会这样做:
var s = function(sketch) {
sketch.setup = function() {
sketch.createCanvas(sketch.windowWidth, sketch.windowHeight);
sketch.background(0);
};
}
new p5(s, "canvas");更多信息可以在p5.js GitHub wiki中找到。
https://stackoverflow.com/questions/43664941
复制相似问题