标签:max 技术 win poi func meta range mouse bar
原生js 移动端可拖拽的进度条
效果图:
代码:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>干货-课程-完成</title> <style> ul.lanren{ margin:100px auto; } .scale_panel{ color:#999; position:absolute; line-height:18px; left:60px;top:-0px; } .scale_panel>span:first-child{ position: absolute; left: -5rem; font-size: 2rem; } .scale_panel>span:nth-child(2){ position: absolute; right: -5rem; font-size: 2rem; } .scale>span{ background-color: red; width:3rem; height:3rem; position:absolute; left:-2px;top:-15px; cursor:pointer; border-radius: 50%; font-size: 2rem; } .scale{ background-repeat: repeat-x; background-position: 0 100%; background-image: linear-gradient(to right,#08D7F2 0%,#2BF06A 50%,#2BF06A 50%,#FC6076 100%); border-left: 1px #83BBD9 solid; width: 43rem; height: 1rem; position: relative; border-radius: 2rem; } .scale>div{ background-repeat: repeat-x; background-color: red; /*进度条颜色*/ width: 0px; position: absolute; height: 1rem; width: 0; left: 0; bottom: 0; border-radius: 2rem; } .lanren>li{ margin-left: 3.5rem; position:relative; list-style:none; font-size: 3rem; } #title{ position: absolute; top: -6rem; left: 23rem; } </style></head><body> <!-- 可拖拽进度条 --> <ul class="lanren"> <li><span id="title">0</span> <div class="scale_panel"> <span class="f-left">吃力</span> <span class="f-right">轻松</span> <div class="scale" id="bar"> <div></div> <span id="btn"></span> </div> </div> </li> </ul> <script src="js/jquery-3.2.1.min.js"></script> <script> // 进度条代码 var scale = function (btn,bar,title){ this.btn=document.getElementById(btn); this.bar=document.getElementById(bar); this.title=document.getElementById(title); this.step=this.bar.getElementsByTagName("div")[0]; this.init(); }; scale.prototype={ init:function (){ var f=this,g=document,b=window,m=Math; f.btn.ontouchstart=function (e){ var x=(e||b.event).touches[0].clientX; var l=this.offsetLeft; var max=f.bar.offsetWidth-this.offsetWidth; g.ontouchmove=function (e){ var thisX=(e||b.event).touches[0].clientX; var to=m.min(max,m.max(-2,l+(thisX-x))); f.btn.style.left=to+‘px‘; f.ondrag(m.round(m.max(0,to/max)*100),to); b.getSelection ? b.getSelection().removeAllRanges() : g.selection.empty(); }; g.ontouchend=new Function(‘this.onmousemove=null‘); }; }, ondrag:function (pos,x){ this.step.style.width=Math.max(0,x)+‘px‘; this.title.innerHTML=pos+‘%‘; } } new scale(‘btn‘,‘bar‘,‘title‘); // }); </script></body></html>
移动端可拖拽的进度条
原文地址:http://www.cnblogs.com/520BigBear/p/7865872.html