游客

音乐播放器,精美简约HTML

一言准备中...

cffe1746354595.jpg

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>白色音乐播放器 - 起风了</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        .player {
            background: white;
            border-radius: 20px;
            padding: 30px;
            width: 350px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            position: relative;
            overflow: hidden;
        }

        .album-art {
            width: 200px;
            height: 200px;
            border-radius: 15px;
            margin: 0 auto 25px;
            overflow: hidden;
            position: relative;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }

        .album-art:hover {
            transform: scale(1.02);
        }

        .album-art img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .song-info {
            text-align: center;
            margin-bottom: 25px;
        }

        .song-title {
            color: #333;
            font-size: 1.3rem;
            margin-bottom: 5px;
            font-weight: 600;
        }

        .artist {
            color: #666;
            font-size: 0.9rem;
        }

        .controls {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 20px;
            margin-bottom: 20px;
        }

        .control-btn {
            background: none;
            border: none;
            color: #666;
            cursor: pointer;
            padding: 10px;
            transition: 0.3s;
            font-size: 1.2rem;
        }

        .control-btn:hover {
            color: #4a90e2;
        }

        .play-btn {
            background: linear-gradient(145deg, #4a90e2, #6ec6ff);
            border-radius: 50%;
            width: 50px;
            height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            box-shadow: 0 5px 15px rgba(74, 144, 226, 0.2);
        }

        .progress-container {
            background: #eee;
            height: 4px;
            border-radius: 2px;
            margin: 15px 0;
            cursor: pointer;
            position: relative;
        }

        .progress {
            background: linear-gradient(to right, #4a90e2, #6ec6ff);
            height: 100%;
            width: 0%;
            border-radius: 2px;
            transition: width 0.1s linear;
        }

        .time {
            display: flex;
            justify-content: space-between;
            color: #888;
            font-size: 0.8rem;
            margin-bottom: 20px;
        }

        .volume-container {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .volume-slider {
            -webkit-appearance: none;
            width: 100px;
            height: 4px;
            background: #eee;
            border-radius: 2px;
        }

        .volume-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 12px;
            height: 12px;
            background: #4a90e2;
            border-radius: 50%;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="player">
        <div class="album-art">
            <img src="https://picsum.photos/200?random=1" alt="专辑封面">
        </div>

        <div class="song-info">
            <h2 class="song-title">起风了</h2>
            <p class="artist">买辣椒也用券</p>
        </div>

        <div class="progress-container">
            <div class="progress"></div>
        </div>

        <div class="time">
            <span class="current-time">0:00</span>
            <span class="duration">0:00</span>
        </div>

        <div class="controls">
            <button class="control-btn prev-btn">⏮</button>
            <button class="control-btn play-btn">▶</button>
            <button class="control-btn next-btn">⏭</button>
        </div>

        <div class="volume-container">
            <span class="control-btn">🔊</span>
            <input type="range" class="volume-slider" min="0" max="1" step="0.1" value="1">
        </div>

        <audio id="audio" src="https://music.163.com/song/media/outer/url?id=1330348068.mp3"></audio>
    </div>

    <script>
        const audio = document.getElementById('audio');
        const playBtn = document.querySelector('.play-btn');
        const progress = document.querySelector('.progress');
        const progressContainer = document.querySelector('.progress-container');
        const volumeSlider = document.querySelector('.volume-slider');
        const currentTimeEl = document.querySelector('.current-time');
        const durationEl = document.querySelector('.duration');

        // 修复后的进度条跳转
        progressContainer.addEventListener('click', (e) => {
            const rect = progressContainer.getBoundingClientRect();
            const pos = (e.clientX - rect.left) / rect.width;
            audio.currentTime = pos * audio.duration;
        });

        // 播放/暂停控制
        playBtn.addEventListener('click', () => {
            if (audio.paused) {
                audio.play();
                playBtn.innerHTML = '⏸';
            } else {
                audio.pause();
                playBtn.innerHTML = '▶';
            }
        });

        // 音量控制
        volumeSlider.addEventListener('input', (e) => {
            audio.volume = e.target.value;
        });

        // 时间更新
        audio.addEventListener('timeupdate', () => {
            const progressPercent = (audio.currentTime / audio.duration) * 100;
            progress.style.width = `${progressPercent}%`;
            currentTimeEl.textContent = formatTime(audio.currentTime);
        });

        // 加载元数据
        audio.addEventListener('loadedmetadata', () => {
            durationEl.textContent = formatTime(audio.duration);
        });

        // 格式化时间
        function formatTime(seconds) {
            const minutes = Math.floor(seconds / 60);
            const secs = Math.floor(seconds % 60);
            return `${minutes}:${secs.toString().padStart(2, '0')}`;
        }

        // 自动播放(需用户交互后生效)
        document.addEventListener('click', () => {
            audio.play();
            playBtn.innerHTML = '⏸';
        }, { once: true });
    </script>
</body>
</html>
  • 本文作者:菜鬼
  • 本文链接: https://www.caigui.net/yin-yue-bo-fang-qi--jing-mei-jian-yao-html.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
1
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
166
5
0
1
梦想不大,创造神话。

现代风格搜索框设计HTML

上一篇

无更多文章

下一篇
评论区
内容为空

这一切,似未曾拥有