js进度条的拉动效果

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
     <style>
         *{
             padding: 0;
             margin: 0;
         }
        .show{
            width:100px ;
            height: 100px;
            background-color: red;
            position: absolute;
            top:-25px;
            z-index: 1;
        }
        .article{
            width: 500px;
            height: 50px;
            position: relative;
            top: 100px;
            left: 100px;
            border: 1px solid red;
        }
        .hidden{
            height: 50px;
            width: 0px;
            position: absolute;
            background-color: red;
            z-index: 1;
        }
        b{
            margin: 100px;
        }
     </style>
    </head>
    <body>
    <div class="article">
        <div class="show">
        </div>
        <div class="hidden">
        </div>
    </div>
    <b>0%</b>
    <script>
        var art=document.querySelector('.article')
        var show=document.querySelector('.show')
        var hidden=document.querySelector('.hidden')
        var data=document.querySelector('b')
        show.οnmοusedοwn=function(e){
            var a=e.offsetX
            var b=e.offsetY
            document.οnmοusemοve=function(e){
                var x=e.clientX-a-show.offsetParent.offsetLeft
               if(x<0){
                   x=0
               }else if(x>show.offsetParent.offsetWidth-show.offsetWidth){
                   x=show.offsetParent.offsetWidth-show.offsetWidth
               }
               show.style.left = x+'px'
               hidden.style.width=x+'px'
               data.innerHTML=(x/(show.offsetParent.offsetWidth-show.offsetWidth)*100).toFixed(0)+'%'
            }
        }
        show.οnmοuseup=function(){
            document.οnmοusemοve=null
        }
    </script>
    </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值