JS 雪花掉落(F12 Console里执行)

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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值