安阳人论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3891|回复: 0

很漂亮的一段网页飘雪代码

[复制链接]

121

主题

8

回帖

1000万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10002082
QQ
发表于 2022-1-6 08:58:58 | 显示全部楼层 |阅读模式
<script type="text/javascript">
//~ snow雪花飘落特效
// 设置雪花数量(不建议超过30-40个)
var snowmax = 30
// 设置雪的颜色,可添加任意颜色
var snowcolor = ["#FFDA65","#00AADD","#aaaacc","#ddddff","#ccccdd","#f3f3f3","#f0ffff","#bbf7f9"]
// 设置创建雪花的字体,可添加任意字体
var snowtype = ["Times","Arial","Verdana"]
// 设置创建雪花的字母(推荐:*)
var snowletter = "*"
// 设置下沉速度(建议值范围为0.3到2)
var sinkspeed = 0.6
// 设置雪花的最大大小
var snowmaxsize = 46
// 设置雪花的最小大小
var snowminsize = 8
// 设置下雪区,1:全屏,2:左侧,3:中间,4:右侧
var snowingzone = 1
///////////////////////////////////////////////////////////////////////////
var snow = []
var marginbottom
var marginright
var timer
var i_snow = 0
var x_mv = []
var crds = []
var lftrght = []
var browserinfos = navigator.userAgent
var ie5 = document.all && document.getElementById && !browserinfos.match(/Opera/)
var ns6 = document.getElementById && !document.all
var opera = browserinfos.match(/Opera/)
var browserok = ie5 || ns6 || opera

function randommaker(range) {
    rand = Math.floor(range * Math.random())
    return rand
}

function initsnow() {
    if (ie5 || opera) {
        marginbottom = document.body.scrollHeight - 80
        marginright = document.body.clientWidth - 15
    } else if (ns6) {
        marginbottom = document.body.scrollHeight - 80
        marginright = window.innerWidth - 15
    }
    var snowsizerange = snowmaxsize - snowminsize
    for (var i = 0;i <= snowmax;i++) {
        crds = 0;
        lftrght = Math.random()*15;
        x_mv = 0.03 + Math.random()/10;
        snow = document.getElementById("s"+i)
        snow.style.fontFamily = snowtype[randommaker(snowtype.length)]
        snow.size = randommaker(snowsizerange)+snowminsize
        snow.style.fontSize = snow.size+'px';
        snow.style.color = snowcolor[randommaker(snowcolor.length)]
        snow.style.zIndex = 1000
        snow.sink = sinkspeed*snow.size/5
        if (snowingzone==1) {snow.posx = randommaker(marginright-snow.size)}
        if (snowingzone==2) {snow.posx = randommaker(marginright/2-snow.size)}
        if (snowingzone==3) {snow.posx = randommaker(marginright/2-snow.size)+marginright/4}
        if (snowingzone==4) {snow.posx = randommaker(marginright/2-snow.size)+marginright/2}
        snow.posy = randommaker(2*marginbottom-marginbottom-2*snow.size)
        snow.style.left=snow.posx+'px';
        snow.style.top=snow.posy+'px';
    }
    movesnow()
}

function movesnow() {
    for (var i = 0;i <= snowmax;i++) {
        crds += x_mv;
        snow.posy+=snow.sink
        snow.style.left = snow.posx+lftrght*Math.sin(crds)+'px';
        snow.style.top = snow.posy+'px';

        if (snow.posy>=marginbottom-2*snow.size || parseInt(snow.style.left)>(marginright-3*lftrght)){
            if (snowingzone==1) {snow.posx = randommaker(marginright-snow.size)}
            if (snowingzone==2) {snow.posx = randommaker(marginright/2-snow.size)}
            if (snowingzone==3) {snow.posx = randommaker(marginright/2-snow.size)+marginright/4}
            if (snowingzone==4) {snow.posx = randommaker(marginright/2-snow.size)+marginright/2}
            snow.posy = 0
        }
    }
    var timer = setTimeout("movesnow()", 50)
}

for (var i = 0;i <= snowmax;i++) {
    document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
}
if (browserok) {
    window.onload = initsnow
}
</script>

我们的动力,源于您的支持!------安阳人论坛,咱安阳人自己的论坛!http://www.ayren.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广告招商
公安部网络违法犯罪举报网站 Internet crime reporting website of the Ministry of public security
公安部网络违法犯罪举报网站!

QQ|Archiver|小黑屋|安阳人论坛

Copyright © 2021 - 2024 安阳人论坛 All Rights Reserved.AyRen.Com

快速回复 返回顶部 返回列表