HTML模块化代码

发布于 更新于
61

1. 页面结构

  • 页头模块 :包含”2026点击许愿”按钮和页面标题
  • 主标题模块 :显示”讯诺源码网”主标题和”源码 · 模板 · 工具”副标题
  • 核心按钮模块 :包含”2026我们马上启航”按钮
  • 用户评论模块 :显示用户头像和评论内容
  • 响应式设计 :适配桌面端、平板端和移动端

2. 交互功能

  • 双按钮弹窗 :
  • 左上角”2026点击许愿”按钮:弹出新年祝福对话框,随机显示20条马年祝福语
  • 核心”2026我们马上启航”按钮:弹出源码网介绍对话框
  • 弹窗控制 :点击关闭按钮或弹窗外部可关闭弹窗
  • 按钮悬停效果 :按钮悬停时会有轻微上浮动画

3. 视觉效果

  • 白色背景 :页面容器使用纯白色背景,简洁干净
  • 蓝色主题 :按钮、边框等使用蓝色#4945ff作为主色调
  • 弹幕效果 :从右侧滑入的弹幕,显示源码网相关内容
  • 用户评论 :使用圆形头像和简洁的评论样式
  • 背景装饰 :左上角和右下角有蓝色点阵装饰

4. 动画效果

  • 弹幕动画 :弹幕从右侧滑入到左侧消失,速度为10-20秒
  • 弹窗动画 :对话框弹出时的淡入效果
  • 按钮动画 :按钮悬停时的微动画
  • 自动弹幕 :每2秒自动生成一条新弹幕,初始加载时生成5条

5. 技术特点

  • 单文件集成 :所有CSS和JavaScript代码都集成在一个HTML文件中,便于引用和部署
  • 模块化设计 :代码结构清晰,易于维护和修改
  • 响应式布局 :在不同屏幕尺寸下都能正常显示
  • 性能优化 :弹幕动画结束后会自动清理,避免内存泄漏
  • 用户体验 :弹窗内容随机显示,增加页面的趣味性

6. 使用场景

  • 作为讯诺源码网的首页或宣传页面
  • 作为源码资源平台的入口页面
  • 可以嵌入到其他网站中作为独立模块使用
    这个页面不仅功能完整,而且视觉效果良好,交互体验流畅,适合作为源码网的展示页面使用。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>讯诺源码网</title>
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background-color: #f8f8f8;
        }

        /* 页面容器 */
        .container {
            position: relative;
            width: 100%;
            margin: 0;
            padding: 20px;
            background-color: #ffffff;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            min-height: 300px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            box-sizing: border-box;
        }

        /* 背景装饰元素 */
        .background-decoration {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            pointer-events: none;
            z-index: 0;
        }

        .background-decoration::before {
            content: '';
            position: absolute;
            top: 10px;
            right: 80px;
            width: 80px;
            height: 80px;
            background-image: radial-gradient(circle, #4945ff 2px, transparent 2px);
            background-size: 8px 8px;
            opacity: 0.5;
        }

        .background-decoration::after {
            content: '';
            position: absolute;
            bottom: 10px;
            left: 80px;
            width: 80px;
            height: 80px;
            background-image: radial-gradient(circle, #4945ff 2px, transparent 2px);
            background-size: 8px 8px;
            opacity: 0.5;
        }

        /* 弹幕容器 */
        .danmaku-container {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            overflow: hidden;
            pointer-events: none;
            z-index: 10;
        }

        /* 弹幕样式 */
        .danmaku {
            position: absolute;
            white-space: nowrap;
            color: white;
            font-size: 12px;
            font-weight: bold;
            padding: 6px 12px;
            border-radius: 16px;
            background-color: rgba(73, 69, 255, 0.7);
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            animation: danmaku-move linear forwards;
            right: -300px;
        }

        /* 弹幕动画 */
        @keyframes danmaku-move {
            from {
                transform: translateX(0);
            }
            to {
                transform: translateX(calc(-100vw - 300px));
            }
        }

        /* 页头模块 */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            position: relative;
            z-index: 1;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .orange-button {
            background-color: #4945ff;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 16px;
            font-size: 12px;
            font-weight: bold;
            cursor: pointer;
        }

        .header-title {
            font-size: 14px;
            color: #333333;
        }

        .header-right {
            display: flex;
            align-items: center;
        }

        .search-text {
            font-size: 12px;
            color: #999999;
            letter-spacing: 1px;
        }

        /* 主标题模块 */
        .main-title-section {
            text-align: center;
            margin-bottom: 20px;
            position: relative;
            z-index: 1;
        }

        .main-title {
            font-size: 24px;
            font-weight: bold;
            color: #333333;
            margin-bottom: 8px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }

        .sub-title {
            font-size: 14px;
            color: #666666;
        }

        /* 核心按钮模块 */
        .core-button-section {
            display: flex;
            justify-content: center;
            margin-bottom: 30px;
            position: relative;
            z-index: 1;
        }

        .core-button {
            background-color: #4945ff;
            color: white;
            border: none;
            padding: 10px 24px;
            border-radius: 24px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 4px 12px rgba(73, 69, 255, 0.4);
            transition: transform 0.3s ease;
        }

        .core-button:hover {
            transform: translateY(-2px);
        }

        .coming-soon {
            font-size: 12px;
            opacity: 0.8;
            margin-left: 8px;
        }

        /* 用户评论模块 */
        .comments-section {
            position: relative;
            z-index: 1;
            min-height: 80px;
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 15px;
            margin-top: 20px;
        }

        .comment-item {
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
            max-width: 100px;
            margin: 8px;
        }

        .avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background-color: #4945ff;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: bold;
            margin-bottom: 6px;
            font-size: 11px;
        }

        .comment-username {
            font-size: 10px;
            color: #333333;
            margin-bottom: 3px;
        }

        .comment-content {
            font-size: 9px;
            color: #666666;
        }

        /* 评论位置 - 移除绝对定位,使用flex布局 */

        /* 对话框样式 */
        .dialog {
            display: none;
            position: fixed;
            z-index: 100;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
        }

        .dialog-content {
            background-color: white;
            margin: 15% auto;
            padding: 24px;
            border-radius: 10px;
            width: 80%;
            max-width: 400px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
            position: relative;
            animation: dialog-fade-in 0.3s ease;
        }

        @keyframes dialog-fade-in {
            from {
                opacity: 0;
                transform: translateY(-50px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .close-button {
            position: absolute;
            right: 15px;
            top: 10px;
            font-size: 20px;
            font-weight: bold;
            cursor: pointer;
            color: #999999;
        }

        .close-button:hover {
            color: #333333;
        }

        .dialog-content h2 {
            color: #4945ff;
            margin-bottom: 16px;
            text-align: center;
            font-size: 18px;
        }

        .dialog-content p {
            margin-bottom: 12px;
            line-height: 1.4;
            color: #333333;
            font-size: 14px;
        }

        .dialog-button {
            display: block;
            width: 100%;
            background-color: #4945ff;
            color: white;
            border: none;
            padding: 10px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: bold;
            cursor: pointer;
            margin-top: 16px;
        }

        .dialog-button:hover {
            background-color: #3a36e6;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                padding: 16px;
                margin: 10px;
                min-height: 250px;
            }

            .main-title {
                font-size: 20px;
            }

            .core-button {
                font-size: 14px;
                padding: 8px 20px;
            }

            .comment-item {
                position: relative;
                top: auto !important;
                left: auto !important;
                right: auto !important;
                bottom: auto !important;
                transform: none !important;
                margin: 8px auto;
                max-width: 100%;
            }

            .comments-section {
                display: flex;
                flex-wrap: wrap;
                justify-content: center;
                gap: 15px;
                margin-top: 20px;
            }

            .dialog-content {
                width: 90%;
                margin: 20% auto;
                padding: 20px;
            }
        }

        @media (max-width: 480px) {
            .header {
                flex-direction: column;
                align-items: flex-start;
                gap: 8px;
            }

            .header-right {
                align-self: flex-end;
            }

            .main-title {
                font-size: 18px;
            }

            .dialog-content {
                width: 95%;
                margin: 30% auto;
                padding: 16px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 背景装饰元素 -->
        <div class="background-decoration"></div>
        
        <!-- 弹幕容器 -->
        <div class="danmaku-container"></div>
        
        <!-- 页头模块 -->
        <header class="header">
            <div class="header-left">
                <button class="orange-button" onclick="openDialog('wish')">2026点击许愿</button>
                <p class="header-title">2026 我在源码网,开启编程新篇章</p>
            </div>
            <div class="header-right">
                <span class="search-text">SEARCH</span>
            </div>
        </header>
        
        <!-- 主标题模块 -->
        <div class="main-title-section">
            <h1 class="main-title">讯诺源码网</h1>
            <p class="sub-title">源码 · 模板 · 工具</p>
        </div>
        
        <!-- 核心按钮模块 -->
        <div class="core-button-section">
            <button class="core-button" onclick="openDialog('source')">2026我们马上启航 <span class="coming-soon">COMING SOON</span></button>
        </div>
        
        <!-- 用户评论模块 -->
        <div class="comments-section">
            <div class="comment-item top-left">
                <div class="avatar">源</div>
                <p class="comment-username">源码爱好者</p>
                <p class="comment-content">讯诺源码网资源真丰富!</p>
            </div>
            
            <div class="comment-item top-right">
                <div class="avatar">码</div>
                <p class="comment-username">码农小王</p>
                <p class="comment-content">在这里找到了很多优质源码</p>
            </div>
            
            <div class="comment-item bottom-left">
                <div class="avatar">网</div>
                <p class="comment-username">网站开发者</p>
                <p class="comment-content">2026年,加油!</p>
            </div>
            
            <div class="comment-item bottom-right">
                <div class="avatar">2026</div>
                <p class="comment-username">2026年的我</p>
                <p class="comment-content">希望能学到更多技术</p>
            </div>
            
            <div class="comment-item bottom-center">
                <div class="avatar">愿</div>
                <p class="comment-username">许愿者</p>
                <p class="comment-content">希望源码网越办越好</p>
            </div>
        </div>
    </div>
    
    <!-- 对话框 -->
    <div id="wish-dialog" class="dialog">
        <div class="dialog-content">
            <span class="close-button" onclick="closeDialog('wish')">&times;</span>
            <h2>2026 新年祝福</h2>
            <p id="blessing-text">在新的一年里,祝你马到成功!</p>
            <button class="dialog-button" onclick="closeDialog('wish')">谢谢祝福</button>
        </div>
    </div>
    
    <!-- 源码网对话框 -->
    <div id="source-dialog" class="dialog">
        <div class="dialog-content">
            <span class="close-button" onclick="closeDialog('source')">&times;</span>
            <h2>讯诺源码网</h2>
            <p>欢迎来到讯诺源码网,您的一站式源码资源平台!</p>
            <p>在这里,您可以找到各种优质源码、网站模板、开发工具,助您快速实现项目开发。</p>
            <button class="dialog-button" onclick="closeDialog('source')">浏览源码</button>
        </div>
    </div>
    
    <script>
        // 马年祝福语
        const blessings = [
            '马年到,祝福到,祝你马到成功,事业有成!',
            '龙马精神,马到功成,万事如意,心想事成!',
            '马年大吉,财运亨通,身体健康,阖家幸福!',
            '一马当先,事业腾飞,前程似锦,步步高升!',
            '马年行大运,好运连连,喜事不断,笑口常开!',
            '万马奔腾,气势如虹,事业兴隆,财源广进!',
            '马到成功,旗开得胜,一帆风顺,吉星高照!',
            '金马送福,福星高照,万事如意,幸福安康!',
            '马年吉祥,大吉大利,心想事成,美梦成真!',
            '扬鞭跃马,大展宏图,事业有成,家庭美满!',
            '马年如意,万事顺心,身体健康,生活幸福!',
            '马不停蹄,勇往直前,事业辉煌,生活美满!',
            '马年好运,财运亨通,事业发达,家庭和睦!',
            '快马加鞭,事业腾飞,财源滚滚,生活幸福!',
            '马年大吉大利,万事如意,心想事成,笑口常开!',
            '龙马精神,意气风发,事业有成,家庭幸福!',
            '马到成功,前程似锦,吉星高照,万事如意!',
            '马年行大运,好运连连,喜事临门,财源广进!',
            '万马奔腾,气势磅礴,事业兴隆,家庭美满!',
            '马年吉祥如意,财运亨通,身体健康,生活幸福!'
        ];

        // 对话框功能
        function openDialog(type) {
            if (type === 'wish') {
                // 随机显示一条祝福语
                const randomBlessing = blessings[Math.floor(Math.random() * blessings.length)];
                document.getElementById('blessing-text').textContent = randomBlessing;
                document.getElementById('wish-dialog').style.display = 'block';
            } else if (type === 'source') {
                document.getElementById('source-dialog').style.display = 'block';
            }
        }

        function closeDialog(type) {
            if (type === 'wish') {
                document.getElementById('wish-dialog').style.display = 'none';
            } else if (type === 'source') {
                document.getElementById('source-dialog').style.display = 'none';
            }
        }

        // 点击对话框外部关闭
        window.onclick = function(event) {
            var wishDialog = document.getElementById('wish-dialog');
            var sourceDialog = document.getElementById('source-dialog');
            if (event.target == wishDialog) {
                wishDialog.style.display = 'none';
            } else if (event.target == sourceDialog) {
                sourceDialog.style.display = 'none';
            }
        }

        // 弹幕功能
        const danmakuContainer = document.querySelector('.danmaku-container');
        const danmakuMessages = [
            '讯诺源码网,源码资源丰富!',
            '2026年,学习源码,提升技能!',
            '源码网,开发者的天堂!',
            '寻找优质源码,就来讯诺源码网!',
            '2026年,源码网伴我成长!',
            '讯诺源码网,值得信赖的源码平台!',
            '学习源码,掌握未来!',
            '源码网,让开发更简单!',
            '2026年,我要成为源码大神!',
            '讯诺源码网,我们的源码之家!'
        ];

        // 生成随机弹幕
        function createDanmaku() {
            const danmaku = document.createElement('div');
            danmaku.className = 'danmaku';
            
            // 随机选择弹幕内容
            const randomMessage = danmakuMessages[Math.floor(Math.random() * danmakuMessages.length)];
            danmaku.textContent = randomMessage;
            
            // 随机位置(垂直方向)
            const top = Math.random() * (danmakuContainer.offsetHeight - 40);
            danmaku.style.top = `${top}px`;
            
            // 随机速度(10-20秒)
            const duration = 10 + Math.random() * 10;
            danmaku.style.animationDuration = `${duration}s`;
            
            // 添加到容器
            danmakuContainer.appendChild(danmaku);
            
            // 动画结束后移除
            setTimeout(() => {
                danmaku.remove();
            }, duration * 1000);
        }

        // 定时生成弹幕
        setInterval(createDanmaku, 2000);

        // 初始生成一些弹幕
        for (let i = 0; i < 5; i++) {
            setTimeout(createDanmaku, i * 1000);
        }
    </script>
</body>
</html>
0 赞
0 收藏
分享
0 讨论
反馈
0 / 600
0 条评论
热门最新
嗨,不要熬夜哦!
所有的成功,都源自一个勇敢的开始