可拖拽的进度条

一.进度条实现:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>可拖拽进度条</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>

图片

实现效果

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值