JavaScript實(shí)現(xiàn)可拖拽的進(jìn)度條
本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)可拖拽的進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下
一.進(jìn)度條實(shí)現(xiàn)
<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>可拖拽進(jìn)度條</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>
二.實(shí)現(xiàn)效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Javascript將雙字節(jié)字符轉(zhuǎn)換成單字節(jié)字符并計(jì)算長(zhǎng)度
這篇文章主要介紹Javascript將雙字節(jié)字符轉(zhuǎn)換成單字節(jié)字符并計(jì)算長(zhǎng)度的方法,簡(jiǎn)單實(shí)用,需要的朋友可以參考下。2016-06-06
HTML中Select不用Disabled實(shí)現(xiàn)ReadOnly的效果
Disabled ReadOnly之家的聯(lián)系2008-04-04
JS+CSS實(shí)現(xiàn)隨機(jī)點(diǎn)名(實(shí)例代碼)
本文通過(guò)js html和cass代碼實(shí)現(xiàn)了隨機(jī)點(diǎn)名效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-11-11
詳解JavaScript中js對(duì)象與JSON格式字符串的相互轉(zhuǎn)換
本篇文章主要介紹了JavaScript中js對(duì)象與JSON格式字符串的相互轉(zhuǎn)換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-02-02
JS/jQuery實(shí)現(xiàn)超簡(jiǎn)單的Table表格添加,刪除行功能示例
這篇文章主要介紹了JS/jQuery實(shí)現(xiàn)超簡(jiǎn)單的Table表格添加,刪除行功能,結(jié)合實(shí)例形式詳細(xì)分析了JS與jQuery針對(duì)Table表格添加,刪除行功能的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-07-07
使用Taro實(shí)現(xiàn)小程序商城的購(gòu)物車功能模塊的實(shí)例代碼
這篇文章主要介紹了使用Taro實(shí)現(xiàn)的小程序商城的購(gòu)物車功能模塊,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06
JS實(shí)現(xiàn)css hover操作的方法示例
這篇文章主要介紹了JS實(shí)現(xiàn)css hover操作的方法,涉及javascript事件響應(yīng)及頁(yè)面元素css屬性動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-04-04

