三明市,福建省辖地级市,位于福建省中部连接西北隅,地处北纬25°30′~27°07′、东经116°22′~118°39′之间,全市面积22965平方千米;东依福州市,西毗江西省,南邻泉州市,北傍南平市,西南接龙岩市; [1] 是一座新兴的工业城市,是全国文明城市和国家卫生城市、国家园林城市及中国优秀旅游城市。 [2] 2016年9月,被国家林业局授予“国家森林城市”称号。 [3] 2017年,三明市复查确认继续保留全国文明城市荣誉称号。 [4]
三明市拥有海峡两岸(三明)现代林业合作实验区,是全国集体林业综合改革试验示范区,享有福建“绿色宝库”的美誉,是全国四个活立木蓄积量超过1亿立方米的设区市之一。截至2015年6月,已发现金属和非金属矿种79个,已探明储量的矿种49种,已开发利用的43种。全市拥有泰宁世界自然遗产地、世界地质公园2个世界级品牌和国家级、省级旅游品牌各50多个,数量和等级名列全省前茅。 [2]
这篇文章主要是用来总结之前的那两篇文章的知识点,分别是《处理数组循环中删除元素导致索引错位情况》和《JavaScript规则图形碰撞原理》,还是用demo来总结来得实在,做了个生成随机圆形,随机颜色,随机位置,不重叠的小demo。demo的js代码如下:
复制代码function creatDiv(r_w){ var randomWidth=parseInt(Math.random()*r_w+50); var allEle=document.getElementById("page467").getElementsByTagName("*"); var div=document.createElement("div"); var bottom=parseInt(Math.random()*(document.body.clientHeight-randomWidth)); var left=parseInt(Math.random()*(document.body.clientWidth-randomWidth)); div.setAttribute("class","lucky-circle"); div.setAttribute("data-left",left); div.setAttribute("data-bottom",bottom); div.style.bottom=bottom+"px"; div.style.left=left+"px"; div.style.backgroundColor="rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")"; div.style.width=randomWidth+"px"; div.style.height=randomWidth+"px"; for(let i=allEle.length-1;i>0;i--){ if(allEle[i].getAttribute("data-left")){ let tLeft=parseInt(allEle[i].getAttribute("data-left")); let tBottom=parseInt(allEle[i].getAttribute("data-bottom")); let width=allEle[i].offsetWidth; let height=allEle[i].offsetHeight; let point_x_1=tLeft+width/2; let point_y_1=tBottom+height/2; let point_x_2=left+randomWidth/2; let point_y_2=bottom+randomWidth/2; let distant= Math.sqrt(Math.pow(Math.abs(point_x_1-point_x_2),2)+Math.pow(Math.abs(point_y_1-point_y_2),2)); if(distant<width/2+randomWidth/2){ allEle[i].parentNode.removeChild(allEle[i]); } } } document.getElementById("page467").appendChild(div);}document.onkeydown=function(){ creatDiv(150);};复制代码