JavaScript implements draggable progress bar

JavaScript implements draggable progress bar

This article shares the specific code of JavaScript to implement a draggable progress bar for your reference. The specific content is as follows

1. Progress bar implementation

<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta charset="UTF-8">
<title>Draggable progress bar</title>
<style>
body{
 margin:50px; ; 
}

.box {
  width:49%;
  hegiht:3rem;
  line-height:3rem;
  float:left;
}
.boxDesc {
  width:50%;
  hegiht:3rem;
  line-height:0.3rem;
  float:left;
}

.scale span{
 background:url(scroll.gif) no-repeat; 
 width:8px;
 height:16px; 
 position:absolute; 
 left:-2px;
 top:-5px;
 cursor:pointer;
}
.scale{ background-repeat: repeat-x; background-position: 0 100%; background-color: #E4E4E4; border-left: 1px #83BBD9 solid; width: 100%; height: 10px; position: relative; font-size: 0px; border-radius: 3px; }
.scale div{ background-repeat: repeat-x; background-color: green; position: absolute; height: 10px; left: 0; bottom: 0; }
li{
 font-size:12px;
 line-height:50px;
 position:relative; 
 height:50px; 
 list-style:none;
}
</style>
</head>
<body>
<ul style='width:100%;margin-top:15rem;'>
 <li>
    <div class = 'box'>
  <div class="scale" id="bar">
   <div></div>
   <span id="btn"></span>
  </div> 
    </div>
  <div class='boxDesc'>
  <span id="title">0</span>
  </div>
 </li>

</ul>
</body>
<script>
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.onmousedown=function (e){
   var x=(e||b.event).clientX;
   var l=this.offsetLeft;
   var max=f.bar.offsetWidth-this.offsetWidth;
   g.onmousemove=function (e){
    var thisX=(e||b.event).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.onmouseup=new Function('this.οnmοusemοve=null');
  };
 },
 ondrag:function (pos,x){
  this.step.style.width=Math.max(0,x)+'px';
  this.title.innerHTML=pos+'%';
 }
}
new scale('btn','bar','title');
</script>
</html>

2. Achievement Effect

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JS implements dragging the progress bar to change the transparency of elements
  • JavaScript implements horizontal progress bar drag effect
  • js to achieve sliding progress bar effect
  • JS implements circular progress bar drag and slide

<<:  mysql installer community 8.0.12.0 installation graphic tutorial

>>:  Sample code for installing ElasticSearch and Kibana under Docker

Recommend

The marquee element implements effects such as scrolling fonts and pictures

The marquee element can achieve simple font (image...

Vue implements fuzzy query-Mysql database data

Table of contents 1. Demand 2. Implementation 3. ...

Explanation of the process of docker packaging node project

As a backend programmer, sometimes I have to tink...

In-depth explanation of environment variables and configuration files in CentOS

Preface The CentOS environment variable configura...

Install mysql offline using rpm under centos 6.4

Use the rpm installation package to install mysql...

Linux installation MySQL tutorial (binary distribution)

This tutorial shares the detailed steps of instal...

Native js to realize a simple snake game

This article shares the specific code of js to im...

The viewport in the meta tag controls the device screen css

Copy code The code is as follows: <meta name=&...

React implements a highly adaptive virtual list

Table of contents Before transformation: After tr...

Detailed explanation of the payment function code of the Vue project

1. Alipay method: Alipay method: Click Alipay to ...