创建一个简洁而美观的百分比进度动画,执行一次后停止在最后一帧

我将创建一个简洁而美观的百分比进度动画,执行一次后停止在最后一帧。

设计思路

  • 创建一个圆形进度条,从0%到100%的动画
  • 使用纯CSS实现,无需JavaScript
  • 添加数字计数器同步显示进度
  • 使用现代UI设计,带有阴影和渐变效果

最终实现代码

<!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 {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding: 20px;
        }
        
        .container {
            text-align: center;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            max-width: 500px;
            width: 100%;
        }
        
        h1 {
            color: white;
            margin-bottom: 30px;
            font-weight: 300;
            font-size: 2.2rem;
        }
        
        .progress-container {
            position: relative;
            width: 200px;
            height: 200px;
            margin: 0 auto 30px;
        }
        
        .progress-circle {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background: conic-gradient(#4cd964 0%, #3498db 0%, #e0e0e0 0%);
            display: flex;
            justify-content: center;
            align-items: center;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
            animation: progress 5s ease forwards;
        }
        
        .progress-inner {
            width: 160px;
            height: 160px;
            background: white;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 2.5rem;
            font-weight: bold;
            color: #333;
            box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .percentage {
            font-size: 2.5rem;
            font-weight: bold;
            color: white;
            margin-bottom: 20px;
        }
        
        .description {
            color: rgba(255, 255, 255, 0.8);
            line-height: 1.6;
            margin-bottom: 25px;
        }
        
        .restart-btn {
            background: rgba(255, 255, 255, 0.2);
            border: 2px solid white;
            color: white;
            padding: 12px 30px;
            border-radius: 50px;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            outline: none;
        }
        
        .restart-btn:hover {
            background: white;
            color: #6a11cb;
        }
        
        @keyframes progress {
            0% {
                background: conic-gradient(#4cd964 0%, #3498db 0%, #e0e0e0 0%);
            }
            100% {
                background: conic-gradient(#4cd964 100%, #3498db 100%, #e0e0e0 0%);
            }
        }
        
        @keyframes count {
            0% {
                content: "0%";
            }
            100% {
                content: "100%";
            }
        }
        
        .percentage::after {
            content: "0%";
            animation: count 5s ease forwards;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>百分比进度动画</h1>
        <div class="progress-container">
            <div class="progress-circle">
                <div class="progress-inner">
                    <span class="percentage"></span>
                </div>
            </div>
        </div>
        <p class="description">这个动画使用纯CSS实现,执行5秒后停止在100%的完成状态。</p>
        <button class="restart-btn" onclick="restartAnimation()">重新开始动画</button>
    </div>

    <script>
        function restartAnimation() {
            // 重新加载页面以重启动画
            location.reload();
        }
    </script>
</body>
</html>

功能说明

  1. 动画效果
    • 圆形进度条从0%到100%填充
    • 数字百分比同步从0%增加到100%
    • 动画持续5秒,使用ease缓动函数
    • 动画执行一次后停止在最后一帧(100%)
  2. 设计特点
    • 使用conic-gradient创建圆形进度条
    • 毛玻璃效果背景
    • 响应式设计,适应不同屏幕尺寸
    • 优雅的阴影和渐变效果
  3. 交互功能
    • 点击”重新开始动画”按钮可以重新观看动画

这个实现完全符合您的要求,动画执行一次后停止在最后一帧,无需任何JavaScript控制动画过程(除了重新开始功能)。

作者:terry,如若转载,请注明出处:https://www.web176.com/news/frontend/28614.html

(1)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2025年8月25日 下午2:57
下一篇 2023年7月25日 下午10:24

相关推荐

发表回复

登录后才能评论