水墨风格动画特效

该文章已生成可运行项目,

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

<!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>
        body {
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            overflow: hidden;
            font-family: 'SimSun', '宋体', serif;
        }
        
        .container {
            position: relative;
            width: 100vw;
            height: 100vh;
            background: linear-gradient(to bottom, #e0e0e0, #f9f9f9);
            overflow: hidden;
        }
        
        .ink-drop {
            position: absolute;
            border-radius: 50%;
            background: radial-gradient(circle, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 70%);
            filter: blur(5px);
            transform: scale(0);
            animation: inkSpread 4s ease-out forwards;
            opacity: 0.7;
        }
        
        @keyframes inkSpread {
            0% {
                transform: scale(0);
                opacity: 0;
            }
            20% {
                opacity: 0.7;
            }
            100% {
                transform: scale(1);
                opacity: 0;
            }
        }
        
        .chinese-char {
            position: absolute;
            font-size: 60px;
            color: rgba(0, 0, 0, 0.7);
            opacity: 0;
            animation: fadeInOut 6s ease-in-out infinite;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }
        
        @keyframes fadeInOut {
            0%, 100% {
                opacity: 0;
                transform: translateY(20px);
            }
            50% {
                opacity: 0.8;
                transform: translateY(0);
            }
        }
        
        .mountain {
            position: absolute;
            bottom: 0;
            width: 100%;
            height: 200px;
            background: linear-gradient(to top, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0) 100%);
            clip-path: polygon(0% 100%, 10% 70%, 20% 80%, 30% 60%, 40% 90%, 50% 50%, 60% 70%, 70% 40%, 80% 60%, 90% 30%, 100% 100%);
            animation: mountainFade 12s ease-in-out infinite alternate;
        }
        
        @keyframes mountainFade {
            0% {
                opacity: 0.3;
            }
            100% {
                opacity: 0.7;
            }
        }
        
        .music-control {
            position: absolute;
            bottom: 20px;
            right: 20px;
            z-index: 100;
            background: rgba(255,255,255,0.7);
            padding: 10px;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 0 10px rgba(0,0,0,0.2);
            transition: all 0.3s;
        }
        
        .music-control:hover {
            transform: scale(1.1);
            background: rgba(255,255,255,0.9);
        }
        
        .credit {
            position: absolute;
            bottom: 10px;
            left: 10px;
            font-size: 12px;
            color: rgba(0,0,0,0.5);
            z-index: 100;
        }
        
        .credit a {
            color: rgba(0,0,0,0.7);
            text-decoration: none;
        }
        
        .credit a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container" id="canvas">
        <div class="mountain"></div>
    </div>
    
    <div class="music-control" id="musicControl">
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M3 15V9a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
            <path d="M13 19V5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2z"></path>
        </svg>
    </div>
    

    
    <audio id="bgMusic" loop>
        <source src="https://music.163.com/song/media/outer/url?id=1330348068.mp3" type="audio/mpeg">
        您的浏览器不支持音频元素。
    </audio>
    
    <script>
        // 水墨扩散效果
        const container = document.getElementById('canvas');
        const chars = ['道', '禅', '静', '和', '美', '雅', '韵', '墨', '水', '山'];
        
        function createInkDrop(x, y) {
            const ink = document.createElement('div');
            ink.className = 'ink-drop';
            ink.style.left = `${x}px`;
            ink.style.top = `${y}px`;
            ink.style.width = `${Math.random() * 300 + 100}px`;
            ink.style.height = ink.style.width;
            container.appendChild(ink);
            
            // 创建随机汉字
            if (Math.random() > 0.7) {
                const char = document.createElement('div');
                char.className = 'chinese-char';
                char.textContent = chars[Math.floor(Math.random() * chars.length)];
                char.style.left = `${x + Math.random() * 100 - 50}px`;
                char.style.top = `${y + Math.random() * 100 - 50}px`;
                char.style.animationDelay = `${Math.random() * 2}s`;
                container.appendChild(char);
            }
            
            // 动画结束后移除元素
            setTimeout(() => {
                ink.remove();
                const chineseChars = document.querySelectorAll('.chinese-char');
                if (chineseChars.length > 10) {
                    chineseChars[0].remove();
                }
            }, 4000);
        }
        
        // 点击或触摸时创建水墨效果
        container.addEventListener('click', (e) => {
            createInkDrop(e.clientX, e.clientY);
        });
        
        container.addEventListener('touchstart', (e) => {
            e.preventDefault();
            const touch = e.touches[0];
            createInkDrop(touch.clientX, touch.clientY);
        });
        
        // 自动生成一些初始水墨效果
        for (let i = 0; i < 5; i++) {
            setTimeout(() => {
                const x = Math.random() * window.innerWidth;
                const y = Math.random() * window.innerHeight * 0.8;
                createInkDrop(x, y);
            }, i * 800);
        }
        
        // 音乐控制
        const musicControl = document.getElementById('musicControl');
        const bgMusic = document.getElementById('bgMusic');
        let isPlaying = false;
        
        musicControl.addEventListener('click', () => {
            if (isPlaying) {
                bgMusic.pause();
                musicControl.innerHTML = `
                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M3 15V9a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
                        <path d="M13 19V5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2z"></path>
                    </svg>`;
            } else {
                bgMusic.play();
                musicControl.innerHTML = `
                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polygon points="5 3 19 12 5 21 5 3"></polygon>
                    </svg>`;
            }
            isPlaying = !isPlaying;
        });
        
        // 自动播放音乐(需要用户交互后)
        document.body.addEventListener('click', function initAudio() {
            if (!isPlaying) {
                bgMusic.volume = 0.3;
                bgMusic.play();
                isPlaying = true;
                musicControl.innerHTML = `
                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polygon points="5 3 19 12 5 21 5 3"></polygon>
                    </svg>`;
            }
            document.body.removeEventListener('click', initAudio);
        }, { once: true });
    </script>
</body>
</html>

本文章已经生成可运行项目

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值