How to implement a simple progress bar effect in js (code example)
Oct 24, 2018 pm 04:15 PMWhat 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>
Result
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

How to implement page loading progress bar function in JavaScript?

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 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
