爱学习的小菜鸡

欢迎各位朋友关注并点赞

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

制作网页背景-星海特效

制作一个类似下图的网页背景

 制作素材图片(在绿色块上右击鼠标可下载素材图片):

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }

        body{
            background-color: #000;
        }

        span{
            width: 30px;
            height: 30px;
            background: url("images/star.png") no-repeat;
            position: absolute;
            background-size:100% 100%;
            animation: flash 1s alternate infinite;
        }
        
        @keyframes flash {
            0%{opacity: 0;}
            100%{opacity: 1;}
        }

        span:hover{
            transform: scale(3, 3) rotate(180deg) !important;
            transition: all 1s;
        }
    </style>
</head>
<body>

<script>
    window.onload = function () {
        // 1. 求出屏幕的尺寸
        var screenW = document.documentElement.clientWidth;
        var screenH = document.documentElement.clientHeight;

        // 2. 动态创建星星
        for(var i=0; i<150; i++){
            // 2.1 创建星星
            var span = document.createElement('span');
            document.body.appendChild(span);

            // 2.2 随机的坐标
            var x = parseInt(Math.random() * screenW);
            var y = parseInt(Math.random() * screenH);
            span.style.left = x + 'px';
            span.style.top = y + 'px';

            // 2.3 随机缩放
            var scale = Math.random() * 1.5;
            span.style.transform = 'scale('+ scale + ', ' + scale + ')';

            // 2.4 频率
            var rate = Math.random() * 1.5;
            span.style.animationDelay = rate + 's';
        }
    }
</script>
</body>
</html>
复制代码

 

posted on   一定W  阅读(9)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示