模拟播放暂停特效

<!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 {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        
        .player-container {
            text-align: center;
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        
        .play-btn {
            width: 80px;
            height: 80px;
            background-color: #4CAF50;
            border-radius: 50%;
            border: none;
            color: white;
            font-size: 24px;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            margin-bottom: 20px;
        }
        
        .play-btn:hover {
            background-color: #45a049;
            transform: scale(1.05);
        }
        
        .play-btn:active {
            transform: scale(0.95);
        }
        
        .play-icon, .pause-icon {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            transition: opacity 0.3s ease;
        }
        
        .pause-icon {
            opacity: 0;
        }
        
        .playing .play-icon {
            opacity: 0;
        }
        
        .playing .pause-icon {
            opacity: 1;
        }
        
        .progress-container {
            width: 300px;
            height: 6px;
            background-color: #ddd;
            border-radius: 3px;
            margin: 20px auto;
            overflow: hidden;
        }
        
        .progress-bar {
            height: 100%;
            width: 0%;
            background-color: #4CAF50;
            transition: width 0.1s linear;
        }
        
        .time-display {
            display: flex;
            justify-content: space-between;
            margin-top: 5px;
            color: #666;
            font-size: 14px;
        }
        
        .title {
            margin-bottom: 20px;
            color: #333;
        }
        
        .footer {
            margin-top: 30px;
            font-size: 12px;
            color: #999;
        }
        
        .footer a {
            color: #4CAF50;
            text-decoration: none;
        }
        
        .footer a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="player-container">
        <h2 class="title">音乐播放器</h2>
        
        <button class="play-btn" id="playButton">
            <div class="play-icon">▶</div>
            <div class="pause-icon">❚❚</div>
        </button>
        
        <div class="progress-container">
            <div class="progress-bar" id="progressBar"></div>
        </div>
        
        <div class="time-display">
            <span id="currentTime">0:00</span>
            <span id="duration">3:45</span>
        </div>
        
        <div class="footer">

        </div>
    </div>

    <script>
        const playButton = document.getElementById('playButton');
        const progressBar = document.getElementById('progressBar');
        const currentTimeDisplay = document.getElementById('currentTime');
        const durationDisplay = document.getElementById('duration');
        
        let isPlaying = false;
        let progress = 0;
        let interval;
        
        // 模拟音频时长 (3分45秒)
        const totalDuration = 225; // 秒
        
        // 格式化时间为 MM:SS
        function formatTime(seconds) {
            const mins = Math.floor(seconds / 60);
            const secs = Math.floor(seconds % 60);
            return `${mins}:${secs < 10 ? '0' : ''}${secs}`;
        }
        
        // 更新进度条
        function updateProgress() {
            progress += 0.1;
            const percentage = (progress / totalDuration) * 100;
            progressBar.style.width = `${percentage}%`;
            currentTimeDisplay.textContent = formatTime(progress);
            
            if (progress >= totalDuration) {
                clearInterval(interval);
                isPlaying = false;
                playButton.classList.remove('playing');
                progress = 0;
                progressBar.style.width = '0%';
                currentTimeDisplay.textContent = '0:00';
            }
        }
        
        // 播放/暂停按钮点击事件
        playButton.addEventListener('click', function() {
            isPlaying = !isPlaying;
            
            if (isPlaying) {
                playButton.classList.add('playing');
                interval = setInterval(updateProgress, 100);
            } else {
                playButton.classList.remove('playing');
                clearInterval(interval);
            }
        });
        
        // 初始化显示总时长
        durationDisplay.textContent = formatTime(totalDuration);
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值