代码可全部用JavaScript写,也可以用使用CSS添加部分样式。下面代码全部放在头部里面。
window.onload=function(){document.body.bgColor="black";window.setInterval("start1()",1000);}function start1(){var imgObj=document.createElement("img");imgObj.setAttribute("src","img/xingxing.gif");var w=getRandom(13,85);imgObj.setAttribute("width",w);var x=getRandom(0,window.innerWidth-80);var y=getRandom(0,window.innerHeight-80);imgObj.setAttribute("style","position:absolute;left:"+x+"px;top:"+y+"px;");imgObj.setAttribute("onclick","hidden1(this)");//绑定点击事件document.body.appendChild(imgObj);//将对象追加进body}function getRandom(min,max){//返回随机数var num = Math.random()*(max-min)+ 11;return parseInt(num);}function hidden1(obj){document.body.removeChild(obj);}
以下是图片素材:https://img-/07301?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjQ4MzUwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70