Progress Bar 0 to 100% in 10 sec


Progress Bar Example



HTML CODE


<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            box-sizing: border-box;
        }
       
        .progressbar__container {
            max-width: 350px;
            margin: 0 auto;
            margin-top: 10%;
        }
       
        .progressbar__bar {
            height: 27px;
            width: 100%;
            position: relative;
            background-color: #e0c2bc;
        }
       
        label {
            padding-bottom: 10px;
            display: block;
        }
       
        .progressbar__fill {
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            background-image: linear-gradient(to right, #a85948, #65352b);
            width: 0;
            transition: width 0.5s linear;
        }
       
        .progressbar__percentage {
            position: absolute;
            top: 5px;
            left: 50%;
            bottom: 0;
            color: white;
            font-weight: bolder;
            font-family: monospace;
            transition: 1.5s;
        }
    </style>
</head>

<body>
    <div class="progressbar__container">
        <label for="progressbar__bar">Progress Bar :</label>
        <div class="progressbar__bar">
            <div class="progressbar__fill"></div>
            <span class="progressbar__percentage">0%</span>
        </div>
    </div>

    <script>
        let progressBarFill = document.querySelector(".progressbar__fill");
        let percentageNumber = document.querySelector(".progressbar__percentage");
        let percentageWidth = 0;
        let widthInc = 5;

        let progressBarFillInterval = setInterval(function() {
            percentageWidth += widthInc;
            percentageNumber.innerHTML = percentageWidth + "%";
            if (percentageWidth >= 100) {
                window.clearInterval(progressBarFillInterval);
            } else {
                progressBarFill.style.width = percentageWidth + widthInc + "%";
            }
        }, 250);
    </script>

</body>

</html>



See the Pen Untitled by Muhammad Habib (@mhabib555) on CodePen.

Comments

Popular posts from this blog

JS-QR Generator

Input Mask Using Libraries

PHP -Sending Email from Localhost (XAMPP) Using SendinBlue