JavaScript實現(xiàn)可拖拽的進度條
更新時間:2021年05月17日 11:42:23 作者:々橙若℃ №
這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)可拖拽的進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了JavaScript實現(xiàn)可拖拽的進度條的具體代碼,供大家參考,具體內(nèi)容如下
一.進度條實現(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>可拖拽進度條</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>
二.實現(xiàn)效果

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在layer彈層layer.prompt中,修改placeholder的實現(xiàn)方法
今天小編大家分享一篇在layer彈層layer.prompt中,修改placeholder的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09
javascript實現(xiàn)圖片延遲加載方法匯總(三種方法)
看到一些大型網(wǎng)站,頁面如果有很多圖片的時候,當你滾動到相應的行時,當前行的圖片才即時加載的,這樣子的話頁面在打開只加可視區(qū)域的圖片,而其它隱藏的圖片則不加載,一定程序上加快了頁面加載的速度,跟著小編一起學習javascript實現(xiàn)圖片延遲加載吧2015-08-08
javascript中apply和call方法的作用及區(qū)別說明
本篇文章主要是對javascript中apply和call方法的作用及區(qū)別進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
javascript 密碼框防止用戶粘貼和復制的實現(xiàn)代碼
本篇文章主要是對javascript 密碼框防止用戶粘貼和復制的實現(xiàn)代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
javascript 使用for循環(huán)時該注意的問題-附問題總結(jié)
所謂for循環(huán)就是重復的執(zhí)行一段代碼,for循環(huán)也是希望在創(chuàng)建循環(huán)時常會用到的工具,這篇內(nèi)容主要給大家介紹javascript 使用for循環(huán)時該注意的問題-附問題總結(jié),需要的朋友可以參考下2015-08-08
js中將具有數(shù)字屬性名的對象轉(zhuǎn)換為數(shù)組
js中將具有數(shù)字屬性名的對象轉(zhuǎn)換為數(shù)組,雖然不太常用,但我們的確可以給對象添加以數(shù)字為屬性名的屬性2011-03-03
用JavaScript和注冊表腳本實現(xiàn)右鍵收藏Web頁選中文本
用JavaScript和注冊表腳本實現(xiàn)右鍵收藏Web頁選中文本...2007-01-01

