📜  p5.js |显示()函数

📅  最后修改于: 2022-05-13 01:56:37.748000             🧑  作者: Mango

p5.js |显示()函数

show()函数是一个内置函数,用于显示当前元素。使用设置显示:用于样式目的的块

此函数需要 p5.dom 库。因此,在index.html文件的 head 部分添加以下行。


句法:

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();
}

输出:
显示()函数