Home Web Front-end JS Tutorial How to implement a simple progress bar effect in js (code example)

How to implement a simple progress bar effect in js (code example)

Oct 24, 2018 pm 04:15 PM
js progress bar

What this article brings to you is to introduce the method of realizing a simple progress bar effect in js (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Not much to say, just go to the code

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>ProgressBar</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #progress{
            width: 100%;
            height: 30px;
            background: rgb(42, 138, 248);
        }
        #bar{
            width: 1%;
            height: 28px;
            margin-top: 1px;
            background: purple;
        }

    </style>
   
</head>
    <body>
        <div id="progress">
            <div id="bar"></div>
        </div>
        <div><h3 id="text-progress">0%</h3></div>
        <input type="button" id=“btn” value="点击开始" onclick="action()">
    </body>
    <script>
        function action(){
            var iSpeed=1;
            obj=setInterval(function(){
                iSpeed+=1;
                if(iSpeed>=100){    // 设置达到多少进度后停止
                    clearInterval(obj); 
                    }
                bar.style.width=iSpeed+'%';
                document.getElementById('text-progress').innerHTML=iSpeed+'%';

            },100);    // 1s后函数执行一次
        }
        </script>
</html> 
Copy after login

Result

##After I finished writing, I found a bug, click Start and then click Progress again The bar will be executed again

Solution:

1. After clicking start, set the button's disabled to disabled so that it cannot be clicked again

2. Add judgment and give message prompt, if the progress bar is clicked again during progress, an alter prompt will be given

The above is the detailed content of How to implement a simple progress bar effect in js (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use JS and Baidu Maps to implement map pan function How to use JS and Baidu Maps to implement map pan function Nov 21, 2023 am 10:00 AM

How to use JS and Baidu Maps to implement map pan function

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

How to implement page loading progress bar function in JavaScript? How to implement page loading progress bar function in JavaScript? Oct 27, 2023 am 08:57 AM

How to implement page loading progress bar function in JavaScript?

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to create a stock candlestick chart using PHP and JS

How to use JS and Baidu Maps to implement map polygon drawing function How to use JS and Baidu Maps to implement map polygon drawing function Nov 21, 2023 am 10:53 AM

How to use JS and Baidu Maps to implement map polygon drawing function

How to use JS and Baidu Map to implement map click event processing function How to use JS and Baidu Map to implement map click event processing function Nov 21, 2023 am 11:11 AM

How to use JS and Baidu Map to implement map click event processing function

See all articles