js实现滑动进度条效果
网络编程 2021-07-04 14:06www.168986.cn编程入门
这篇文章主要为大家详细介绍了js实现滑动进度条效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了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;:-5px;} .progress-bar .max-num{position:absolute;right:-40px;:-5px;} .progress-bar .block {position:absolute;height:30px;width:10px;background:#c;:-10px;border-radius:10px;} .progress-bar .block div{position:absolute;display:none;left:-20px;:-45px;width:50px;height:30px;text-align:center;line-height:30px;background:#c;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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程