php带滑动的进度条,js实现滑动进度条

afab0bc4d63145e375c18b7a998b9e8b.png

本文实例为大家分享了js实现滑动进度条效果的具体代码,供大家参考,具体内容如下

b32f648299702b3f81fa9022e083017f.gif

进度条:

js滑动进度条效果

*{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 p{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 p{display:block;font-size:10%;color:#fff;background:#409eff;}

0

100

0

(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('p').innerText = percent + '%';

}

};

};

// 鼠标松开移除事件

moveBlock.onmouseup = function(){

document.onmousemove = null;

};

})();

相关图文推荐:js教程(图文)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值