show()函数是一个内置函数,用于显示当前元素。使用设置显示:块用于样式目的。
此函数需要p5.dom库。因此,在index.html文件的开头部分添加以下行。
<script language="javascript"
type="text/javascript" src="path/to/p5.dom.js">
</script>
用法:
show()
参数:该函数不接受任何参数。
下面的示例说明了p5.js中的show()函数:
例:
function setup() {
// Create Canvas of given size
var cvs = createCanvas(600, 250);
}
function draw() {
// Set the background color
background('green');
// Use createDiv() function to
// create a div element
var myDiv1 = createDiv('GeeksforGeeks');
// Set the position of div element
myDiv1.position(170, 30);
// Set the div size
myDiv1.size(200, 100);
// Set the font-size of text
myDiv1.style('font-size', '36px');
// Use createDiv() function to
// create a div element
var myDiv = createDiv('A computer science portal for geeks');
// Set the position of div element
myDiv.position(180, 80);
// Set the div size
myDiv.size(200, 100);
// Set the font-size of text
myDiv.style('font-size', '24px');
// Set the font-size of text
myDiv.style('border', '1px solid black');
// Set the font-size of text
myDiv.style('text-align', 'center');
// Set the font color
myDiv.style('color', 'white');
// Hide the div element
myDiv.hide();
// Show the div element
myDiv.show();
}
输出:
相关用法
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 p5.js | show() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。