function createLayer() {
var div = document.createElement('div');
with(div.style) {
position = 'fixed';
/*position定义布局方式,fixed为相对于浏览器窗口的绝对布局;static为无定位,用来取消继承,还原元素定位的默认值;
*absolute为绝对定位;relative相对定位,即相对于元素默认位置的定位
**/
left = 0;
top = 0;
width = '100%';
height = '100%';
zIndex = 9999;//Z轴,值越大,则在页面的显示越靠外部
background = 'rgba(0,0,0,.5)';//采用RGB颜色(红绿蓝),色彩空间Alpha(设定不透明度参数,0%到100%之间的值)
}
document.body.appendChild(div);//作用可能是使此div跟在body的后面
}
function rand(min, max) {
//random函数是JAVA的随机函数
return Math.round(Math.random() * (max - min + 1)) + min;
}
var xh = [];//定义一个任意数组
function createXh() {
var div = document.createElement('div');
div.innerHTML = String.fromCharCode(10052);
with(div.style) {
color = '#FFF';
position = 'fixed';
left = rand(0, window.innerWidth - 80) + 'px';
top = rand(0, window.innerHeight - 80) + 'px';
fontSize = rand(40, 80);
zIndex = 10000;
}
document.body.appendChild(div);
xh.push(div);
}
createLayer();
var count = 0;
function loop() {
if (++count < 20) {
createXh();
}
for (var i in xh) {
xh[i].style.top = parseInt(xh[i].style.top) + 5 + 'px';
if (parseInt(xh[i].style.top) > window.innerHeight) {
delete xh[i];
createXh();
}
}
setTimeout(loop, 30);
}
loop();
var div = document.createElement('div');
with(div.style) {
position = 'fixed';
/*position定义布局方式,fixed为相对于浏览器窗口的绝对布局;static为无定位,用来取消继承,还原元素定位的默认值;
*absolute为绝对定位;relative相对定位,即相对于元素默认位置的定位
**/
left = 0;
top = 0;
width = '100%';
height = '100%';
zIndex = 9999;//Z轴,值越大,则在页面的显示越靠外部
background = 'rgba(0,0,0,.5)';//采用RGB颜色(红绿蓝),色彩空间Alpha(设定不透明度参数,0%到100%之间的值)
}
document.body.appendChild(div);//作用可能是使此div跟在body的后面
}
function rand(min, max) {
//random函数是JAVA的随机函数
return Math.round(Math.random() * (max - min + 1)) + min;
}
var xh = [];//定义一个任意数组
function createXh() {
var div = document.createElement('div');
div.innerHTML = String.fromCharCode(10052);
with(div.style) {
color = '#FFF';
position = 'fixed';
left = rand(0, window.innerWidth - 80) + 'px';
top = rand(0, window.innerHeight - 80) + 'px';
fontSize = rand(40, 80);
zIndex = 10000;
}
document.body.appendChild(div);
xh.push(div);
}
createLayer();
var count = 0;
function loop() {
if (++count < 20) {
createXh();
}
for (var i in xh) {
xh[i].style.top = parseInt(xh[i].style.top) + 5 + 'px';
if (parseInt(xh[i].style.top) > window.innerHeight) {
delete xh[i];
createXh();
}
}
setTimeout(loop, 30);
}
loop();