首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >永夜星河主题特效(星河背景 + 闪烁文字)

永夜星河主题特效(星河背景 + 闪烁文字)

作者头像
命运之光
发布于 2024-11-17 04:32:26
发布于 2024-11-17 04:32:26
32500
代码可运行
举报
运行总次数:0
代码可运行

图片展示

如果想用前端写一个好看的特效,可以做一个《永夜星河》主题的网页特效,比如星河背景、动态文字、浮动的角色元素等。以下是一个示例,展示星空背景和动态文字特效,同时可以加入与电视剧主题相关的元素。


完整代码
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>永夜星河主题特效</title>
    <style>
        /* 星河背景 */
        body {
            margin: 0;
            overflow: hidden;
            background: radial-gradient(circle, #1a2a6c, #b21f1f, #fdbb2d);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        /* 星星点点 */
        canvas {
            position: absolute;
            top: 0;
            left: 0;
        }

        /* 闪烁文字 */
        .title {
            font-size: 3em;
            font-weight: bold;
            text-transform: uppercase;
            text-shadow: 0 0 20px #fff, 0 0 30px #ff9, 0 0 40px #ff9;
            animation: glow 2s infinite alternate;
        }

        @keyframes glow {
            from {
                text-shadow: 0 0 10px #fff, 0 0 20px #ff9, 0 0 30px #ff9;
            }
            to {
                text-shadow: 0 0 30px #ff9, 0 0 50px #ff9, 0 0 70px #ff9;
            }
        }

        /* 动态漂浮图片 */
        .character {
            position: absolute;
            bottom: 10%;
            width: 150px;
            animation: float 4s ease-in-out infinite;
        }

        @keyframes float {
            0%, 100% {
                transform: translateY(0);
            }
            50% {
                transform: translateY(-20px);
            }
        }
    </style>
</head>
<body>
    <!-- 星河背景 -->
    <canvas id="stars"></canvas>

    <!-- 闪烁文字 -->
    <div class="title">永夜星河</div>

    <!-- 动态漂浮角色 -->
    <img src="character.png" alt="角色" class="character">

    <script>
        // 星星特效
        const canvas = document.getElementById('stars');
        const ctx = canvas.getContext('2d');
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        let stars = [];
        const numStars = 100;

        // 初始化星星
        for (let i = 0; i < numStars; i++) {
            stars.push({
                x: Math.random() * canvas.width,
                y: Math.random() * canvas.height,
                radius: Math.random() * 1.5,
                speed: Math.random() * 0.5
            });
        }

        // 绘制星星
        function drawStars() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.fillStyle = 'white';
            stars.forEach(star => {
                ctx.beginPath();
                ctx.arc(star.x, star.y, star.radius, 0, Math.PI * 2);
                ctx.fill();
                star.y += star.speed;
                if (star.y > canvas.height) {
                    star.y = 0;
                }
            });
            requestAnimationFrame(drawStars);
        }

        drawStars();
    </script>
</body>
</html>
功能说明:
  1. 星河背景
    • 使用 CSS 和 Canvas 绘制动态背景,模拟流动的星河效果。
  2. 闪烁文字特效
    • 通过 @keyframes 实现文字的光晕动画,模拟星河的闪烁感。
  3. 动态漂浮角色
    • 可使用剧中角色的图片,设置漂浮动画(需要替换 character.png 为合适图片)。

使用说明:
  1. 角色图片: 将剧中角色的图片保存为 character.png,放置在与 HTML 同目录下。
  2. 优化细节
    • 可以将背景音乐或鼠标交互(例如移动星星)加入其中,增加趣味性。
    • 使用 WebGL(如 Three.js)可进一步增强星空效果。

运行后,这个网页将展现动态的星空背景、闪烁的“永夜星河”文字和漂浮的角色,带来沉浸式的视觉体验!

嗨,我是命运之光。如果你觉得我的分享有价值,不妨通过以下方式表达你的支持:👍 点赞来表达你的喜爱,📁 关注以获取我的最新消息,💬 评论与我交流你的见解。我会继续努力,为你带来更多精彩和实用的内容。

点击这里👉 ,获取最新动态,⚡️ 让信息传递更加迅速。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-11-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验