createSpan()函数用于使用给定的可选内部html在DOM中创建span元素。
用法:
createSpan([html])
参数:该函数接受如上所述和以下描述的单个参数:
- html:它是一个带有span元素的innerHTML的字符串。它是一个可选参数。
返回值:它返回一个指向具有已创建节点的p5.Element的指针。
以下示例说明了p5.js中的createSpan()函数:
例:
function setup() { 
  createCanvas(600, 300); 
   
  textSize(18); 
  text("Click on the button to create" + 
       "<span> elements at random positions.", 20, 20) 
  genBtn = createButton("Create span element").position(30, 40); 
  genBtn.mousePressed(spawnSpan); 
} 
   
function spawnSpan() { 
  newSpan = createSpan("This is a <b>span</b> element"+ 
                       " with custom <i>innerHTML</i>."); 
  newSpan.position(random(50, 500), random(50, 300)); 
}输出:

参考: https://p5js.org/reference/#/p5/createSpan
相关用法
- PHP max( )用法及代码示例
- p5.js nf()用法及代码示例
- PHP dir()用法及代码示例
- PHP pi( )用法及代码示例
- p5.js min()用法及代码示例
- p5.js box()用法及代码示例
- CSS rgb()用法及代码示例
- PHP pow( )用法及代码示例
- PHP Ds\Set xor()用法及代码示例
- p5.js nfc()用法及代码示例
- p5.js nfp()用法及代码示例
- p5.js nfs()用法及代码示例
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 p5.js | createSpan() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
