JavaScript implements native code for progress bar
In our daily development work, I believe that our friends should be familiar with Progress bar. The progress bar still plays a very important role in our project, so today we will give you the details Introducing the JavaScript example analysis of implementing the progress bar!
setTimeout and clearTimeou
<html> <head> <title>进度条</title> <style type="text/css"> .container{ width:450px; border:1px solid #6C9C2C; height:25px; } #bar{ background:#95CA0D; float:left; height:100%; text-align:center; line-height:150%; } </style> <script type="text/javascript"> function run(){ var bar = document.getElementById("bar"); var total = document.getElementById("total"); bar.style.width=parseInt(bar.style.width) + 1 + "%"; total.innerHTML = bar.style.width; if(bar.style.width == "100%"){ window.clearTimeout(timeout); return; } var timeout=window.setTimeout("run()",100); } window.onload = function(){ run(); } </script> </head> <body> <div class="container"> <div id="bar" style="width:0%;"></div> </div> <span id="total"></span> </body> </html>
Rendering:
<html> <head> <title>进度条</title> <style type="text/css"> .processcontainer{ width:450px; border:1px solid #6C9C2C; height:25px; } #processbar{ background:#95CA0D; float:left; height:100%; text-align:center; line-height:150%; } </style> <script type="text/javascript"> function setProcess(){ var processbar = document.getElementById("processbar"); processbar.style.width = parseInt(processbar.style.width) + 1 + "%"; processbar.innerHTML = processbar.style.width; if(processbar.style.width == "100%"){ window.clearInterval(bartimer); } } var bartimer = window.setInterval(function(){setProcess();},100); window.onload = function(){ bartimer; } </script> </head> <body> <div class="processcontainer"> <div id="processbar" style="width:0%;"></div> </div> </body> </html>
Rendering:
3. The difference between setTimeout and setInterval
setTimeout() only executes the code once. If you want to call it multiple times, use setInterval(). The setInterval() method will keep calling the function until clearInterval() is called or the window is closed, or the code itself calls setTimeout() again.
Summary:
# I believe that through studying this article, you will have a better understanding of the JavaScript implementation of the progress bar. When you encounter When you meet the same requirement, you can refer to this article. I hope it will be helpful to you!
Related recommendations:
JS native upload large file display progress bar-php file upload
Instance of JavaScript implementing progress bar based on timer
JavaScript implementing audio control progress bar
Introduction to the method of displaying the process progress bar by combining JS and HTML
The above is the detailed content of JavaScript implements native code for progress bar. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

The win10 system is a very excellent high-intelligence system. Its powerful intelligence can bring the best user experience to users. Under normal circumstances, users’ win10 system computers will not have any problems! However, it is inevitable that various faults will occur in excellent computers. Recently, friends have been reporting that their win10 systems have encountered frequent blue screens! Today, the editor will bring you solutions to different codes that cause frequent blue screens in Windows 10 computers. Let’s take a look. Solutions to frequent computer blue screens with different codes each time: causes of various fault codes and solution suggestions 1. Cause of 0×000000116 fault: It should be that the graphics card driver is incompatible. Solution: It is recommended to replace the original manufacturer's driver. 2,

Termination Code 0xc000007b While using your computer, you sometimes encounter various problems and error codes. Among them, the termination code is the most disturbing, especially the termination code 0xc000007b. This code indicates that an application cannot start properly, causing inconvenience to the user. First, let’s understand the meaning of termination code 0xc000007b. This code is a Windows operating system error code that usually occurs when a 32-bit application tries to run on a 64-bit operating system. It means it should

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

If you need to program any device remotely, this article will help you. We will share the top GE universal remote codes for programming any device. What is a GE remote control? GEUniversalRemote is a remote control that can be used to control multiple devices such as smart TVs, LG, Vizio, Sony, Blu-ray, DVD, DVR, Roku, AppleTV, streaming media players and more. GEUniversal remote controls come in various models with different features and functions. GEUniversalRemote can control up to four devices. Top Universal Remote Codes to Program on Any Device GE remotes come with a set of codes that allow them to work with different devices. you may

What does the 0x000000d1 blue screen code mean? In recent years, with the popularization of computers and the rapid development of the Internet, the stability and security issues of the operating system have become increasingly prominent. A common problem is blue screen errors, code 0x000000d1 is one of them. A blue screen error, or "Blue Screen of Death," is a condition that occurs when a computer experiences a severe system failure. When the system cannot recover from the error, the Windows operating system displays a blue screen with the error code on the screen. These error codes

Quickly get started with Python drawing: code example for drawing Bingdundun Python is an easy-to-learn and powerful programming language. By using Python's drawing library, we can easily realize various drawing needs. In this article, we will use Python's drawing library matplotlib to draw a simple graph of ice. Bingdundun is a cute panda who is very popular among children. First, we need to install the matplotlib library. You can do this by running in the terminal

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest
