美文网首页
进度条的实现

进度条的实现

作者: daisx | 来源:发表于2017-04-27 19:28 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }
            #box{width: 1000px;height: 37px;margin: 100px auto; position: relative;}
            #left{ width: 800px;height: 35px;background: #ccc; position: absolute;!important;}
            #right{width: 35px;height:35px;position: absolute;right: 150px;line-height: 35px;text-align: center;
             border-top-left-radius: 10px; border-bottom-left-radius: 10px;
            }
            #mark{width: 35px;height: 45px;background: orangered;border-radius: 10px;position: absolute;left: 0px;top: -4px;   }
            #hid{
                background: orangered;height: 35px; border-top-left-radius: 10px; width: 0px;
                border-bottom-left-radius: 10px;
            }
        </style>
    </head>
    <body>
    <div id="box">
        <div id="left">
            <div id="hid"></div>
            <span id="mark"></span>
        </div>
        <div id="right">0%</div>
    </div>
    
    <script>
        window.onload = function () {
            var oBox=document.getElementById("box");
            var oLt=document.getElementById("left");
            var oRt=document.getElementById("right");
            var oMak=document.getElementById("mark");
            var oHdn=document.getElementById("hid");
    
            oMak.onmousedown= function (event) {
                var event=event||document.event;
                var oMarkPoint=event.clientX-oMak.offsetLeft;
                document.onmousemove= function (event) {
                    var event=event||document.event;
                    var move=event.clientX-oMarkPoint;
                    if(move<=0){
                        move=0
                    }else if(move>=765){
                        move=765;
                    }
                    oMak.style.left=move+"px";
                    oHdn.style.width=move+"px"
                   oRt.innerHTML=parseInt((move/765)*100)+"%";
                }
                document.onmouseup = function () {
                    document.onmousemove = null;
                    document.onmouseup = null;}
            }
        }
    </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:进度条的实现

          本文链接:https://www.haomeiwen.com/subject/cisnzttx.html