js滑动进度条效果

  • <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>js滑动进度条效果</title>
        <style>
          *{margin:0;padding:0;user-select:none;}
          .progress-bar{position:relative;height:10px;width:400px;margin:200px auto;background:#ebeef5;border-radius:10px;}
          .progress-bar .pro-bar{position:absolute;left:0;height:10px;width:10px;background:#409eff;}
          .progress-bar .min-num{position:absolute;left:-20px;top:-5px;}
          .progress-bar .max-num{position:absolute;right:-40px;top:-5px;}
          .progress-bar .block {position:absolute;height:30px;width:10px;background:#ccc;top:-10px;border-radius:10px;}
          .progress-bar .block div{position:absolute;display:none;left:-20px;top:-45px;width:50px;height:30px;text-align:center;line-height:30px;background:#ccc;border-radius:20px;}
          .progress-bar .block:hover div{display:block;font-size:10%;color:#fff;background:#409eff;}
        </style>
    </head>
    <body>
      <div class="progress-bar">
        <span class="min-num">0</span>
        <span class="max-num">100</span>
        <div class="pro-bar"></div>
        <div class="block">
          <div>0</div>
        </div>
      </div>
    </body>
    <script>
      (function(){
        let moveBlock = document.querySelector('.block');
        let proBar = document.querySelector('.pro-bar');
        let flag = false;
        let startX = null;
        let moveMax = (400 - 10); // 背景条宽度减去滑块的宽度
        moveBlock.onmousedown = function(e){
          startX = e.pageX;
          moveBlock.style.left ? moveBlock.style.left : moveBlock.style.left = '0px';
          let startLeft = parseInt(moveBlock.style.left);
          document.onmousemove = function(e){
            let moveX = (e.pageX - startX) > 0 ? true : false;
            let moveSection = startLeft + (e.pageX - startX);
            // 限定移动范围
            if (moveSection >= 0 && moveSection <= moveMax) {
              let percent = ((startLeft + (e.pageX - startX)) / moveMax).toFixed(4) * 100;
              percent.toString().length > 5 ? percent = percent.toString().subStr(0, 5) : percent = percent.toString();
              moveBlock.style.left = startLeft + (e.pageX - startX) + 'px';
              proBar.style.width = moveBlock.style.left;
              moveBlock.querySelector('div').innerText = percent + '%';
            }
          };
        };
        // 鼠标松开移除事件
        moveBlock.onmouseup = function(){
          document.onmousemove = null;
        };
      })();
    </script>
    </html>
    

     

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用是一个小程序的wxml代码,其中包含了两个圆环进度条的实例。每个圆环进度条组件被包裹在一个view标签中,并设置了相应的属性,如canvasWidth、value、valueColor和lineWidth等。引用是该小程序的目录结构图,其中包含了使用到的组件circle的路径。引用是该小程序的js代码,其中使用setInterval函数每隔1秒更新了两个圆环进度条的值per和per1。 根据提供的信息,我了解到你想实现一个vue环形进度条滑动效果。在Vue中,你可以使用第三方库或者自定义组件来实现这个效果。一个常见的库是vue-circle-progress,它提供了一个圆环进度条组件可以实现滑动效果。你可以按照该库的文档来安装和使用该组件。 另外,你也可以自定义一个组件来实现环形进度条滑动效果。你可以使用Vue的transition和animation属性来实现动画效果,并通过改变数据的值来实现进度条滑动。 希望这些信息对你有帮助,如果你需要更详细的代码实现或者其他信息,请提供更多的上下文。123 #### 引用[.reference_title] - *1* *2* *3* [微信小程序环形进度条模块](https://blog.csdn.net/weixin_46043195/article/details/126305486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值