移除由p5.js创建的所有元素,包括任何事件处理程序。
有两个例外:通过createCanvas()创建的画布元素和通过createGraphics()创建的p5.Render对象。
示例
function setup() {
createCanvas(100, 100);
background(200);
// Create a paragraph element and place
// it in the middle of the canvas.
let p = createP('p5*js');
p.position(25, 25);
describe('A gray square with the text "p5*js" written in its center. The text disappears when the mouse is pressed.');
}
// Remove all elements when the mouse is pressed.
function mousePressed() {
removeElements();
}
let slider;
function setup() {
createCanvas(100, 100);
// Create a paragraph element and place
// it at the top of the canvas.
let p = createP('p5*js');
p.position(25, 25);
// Create a slider element and place it
// beneath the canvas.
slider = createSlider(0, 255, 200);
slider.position(0, 100);
describe('A gray square with the text "p5*js" written in its center and a range slider beneath it. The square changes color when the slider is moved. The text and slider disappear when the square is double-clicked.');
}
function draw() {
// Use the slider value to change the background color.
let g = slider.value();
background(g);
}
// Remove all elements when the mouse is double-clicked.
Notice any errors or typos? Please let us know. Please feel free to edit src/dom/dom.js and open a pull request!