zoukankan      html  css  js  c++  java
  • JavaScript进度条的简单案例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
                #progress{
                    position: relative;
                    margin: auto;
                    top: 200px;
                    display: block;
                     200px;
                    height: 20px;
                    border-style: dotted;
                    border- thin;
                    border-color: darkgreen;
                }
                #filldiv{
                    position:absolute;
                    top: 0px;
                    left: 0px;
                     0px;
                    height: 20px;
                    background: blue;
                }
                #percent{
                    position: absolute;
                    top: 0px;
                    left: 200px;
                }
            </style>
    </head>    
        <body>
            <div id="progress">
                <div id="filldiv"></div>
                <span id="percent">0</span>
            </div>
            <script>
                // 原理就是让里面的div随着定时器 让他的width慢慢增加
    
                // 获取需要操作的dom对象
                var $progress = document.querySelector('#progress');
                var $filldiv = document.querySelector('#filldiv');
                var $percent = document.querySelector('#percent');
    
                // 设置定时器 
                var timer = setInterval(function () {
                    $filldiv.style.width = $filldiv.offsetWidth + 1 + 'px';
                    // 设置百分比与进度条同步
                    $percent.innerHTML = parseInt(($filldiv.offsetWidth/200)*100) + "%";
                    // 当进度条走到顶端 清除定时器
                    if ($filldiv.offsetWidth == 200) {
                        clearInterval(timer);
                    }
                },20);
            </script>
        </body>
    </html>

    如上,比较简单

  • 相关阅读:
    Java 抽象类
    7.队列的链表实现
    6.队列的数组实现
    5.栈的链表实现
    4.栈的数组实现
    3.线性表-cursor
    2.线性表-Linked list
    1.线性表-Array
    hello world!
    boost 大小端转换
  • 原文地址:https://www.cnblogs.com/H-Y-Z/p/10494771.html
Copyright © 2011-2022 走看看