分别设置颜色和字号,使用定位实现不重叠功能。设置字体大小Math.floor(Math.random()*10)+10setColor(){varr=Math.floor(Math.random()*256);varg=Math.floor(Math.random()*256);varb=Math.floor(Math.random()*256);return"rgb("+r+','+g+','+b+")";},setLeft(){returnMath.random()*100*3+200},setTop(){if(this.words.length==this.randomTopArr.length)returnletrandomTxt=Math.random()*100*3randomTxt=randomTxt>230?randomTxt/3:randomTxtthis.randomTopArr.length&&this.randomTopArr.forEach(res=>{if(Math.abs(res-randomTxt)<30){randomTxt=res>randomTxt?randomTxt-20:res-20}}})this.randomTopArr.push(randomTxt)returnrandomTxt}主要思想是设置top值,只??要在一定范围内,区间就不会重叠。使用每个随机生成的最高值与存储数组中的每个项目进行比较。如果距离太近,请进行更改
