[英]Controlling where Canvas is created? P5.js
I've been exploring the p5 docs but haven't found any example on how to control where the canvas is made. 我一直在探索p5文档,但没有找到有关如何控制画布制作位置的任何示例。
I see that createCanvas() has an optional 3rd argument for renderers, but I'm not entirely sure how or if I should implement that. 我看到createCanvas()对于渲染器有一个可选的第3个参数,但是我不确定如何实现或该实现。
Essentially what I have is a modal and I would like to create the canvas inside it. 本质上,我拥有的是模态,并且我想在其中创建画布。
Markup: 标记:
<div>
<div class="IX_recordControls clearfix">
<div class="rcrow canvas">Woof</div> <-- //Let's say I want my canvas here.
</div>
</div>
In my JS file I call createCanvas() in setup() like so: 在我的JS文件中,我在setup()中调用createCanvas(),如下所示:
function setup(){
createCanvas(400, 150)
$s.p5mic = new p5.AudioIn()
$s.p5mic.start()
$s.micIsOn = true
background(155);
draw();
noLoop();
}
How can I can communicate to createCanvas that I want it to be generated inside my modal? 我该如何与我希望在模态内部生成的createCanvas通信?
You can use p5.Element.parent()
function. 您可以使用
p5.Element.parent()
函数。
<div id="sketch-holder">
<!-- Our sketch will go here! -->
</div>
...
var canvas = createCanvas(100, 100);
// Move the canvas so it’s inside our <div id="sketch-holder">.
canvas.parent('sketch-holder');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.