最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

原生JavaScript實(shí)現(xiàn)進(jìn)度條

 更新時(shí)間:2021年02月19日 10:51:53   作者:weixin_44134972  
這篇文章主要為大家詳細(xì)介紹了原生JavaScript實(shí)現(xiàn)進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

JavaScript實(shí)現(xiàn)進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下

進(jìn)度條實(shí)現(xiàn)介紹

使用JavaScript實(shí)現(xiàn)進(jìn)度條功能。

原理:通過鼠標(biāo)移動(dòng)事件,獲取鼠標(biāo)移動(dòng)的距離。

步驟:

(1)html 中 div 布局
(2)css 樣式編寫
(3)JavaScript特效編寫

html代碼

<body>
 <!-- 整體盒子 -->
 <div id="box">
 <!-- 進(jìn)度條整體 -->
 <div id="progress">
 <!-- 進(jìn)度條長度 -->
  <div id="progress_head"></div>
 <!-- 進(jìn)度條移動(dòng)條 -->
 <span id="span"></span>
 <div>
 <!-- 顯示數(shù)據(jù) -->
 <div id="percentage">0%</div>
 </div>
</body>

css樣式

<style>
 /* 整體樣式,消除默認(rèn)樣式 */
 body{
 margin:0;
 padding:0;
 }
 #box{
 position:relative;
 width:1000px;
 height:30px;
 margin:100px auto;
 } 
 #progress{
 position:relative;
 width:900px;
 height:30px;
 background:#999999;
 border-radius:8px;
 margin:0 auto; 
 }
 #progress_head{
 width:0px;
 height:100%;
 border-top-left-radius:8px;
 border-bottom-left-radius:8px;
 background:#9933CC;
 
 }
 span{
 position:absolute;
 width:20px;
 height:38px;
 background:#9933CC;
 top:-4px;
 left:0px;
 cursor:pointer;
 }
 #percentage{
 position:absolute;
 line-height:30px;
 text-align:center;
 right:-44px;
 top:0;
 }
 
 
</style>

JavaScript代碼

<script>

 //js獲取節(jié)點(diǎn)
 var oProgress=document.getElementById('progress');
 var oProgress_head=document.getElementById('progress_head');
 var oSpan=document.getElementById('span');
 var oPercentage=document.getElementById('percentage')

 //添加事件 鼠標(biāo)按下的事件
 oSpan.onmousedown=function(event){
 
 var event=event || window.event;
 var x=event.clientX-oSpan.offsetLeft;

 document.onmousemove=function(){
 
 var event=event || window.event;
 var wX=event.clientX-x;
 
 
 if(wX<0)
 {
  wX=0;
 }else if(wX>=oProgress.offsetWidth-20)
 {
  wX=oProgress.offsetWidth - 20;
 }
 oProgress_head.style.width=wX+'px';
 oSpan.style.left=wX+'px';
 
 oPercentage.innerHTML=parseInt(wX/(oProgress.offsetWidth-20)*100)+'%';
 
 return false;
 };
 
 document.onmouseup=function(){
 
 document.onmousemove=null; 
 };
 
 }; 
</script>

效果圖

整體代碼

<!DOCTYPE>
<html lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>進(jìn)度條</title>
 <style>
 /* 整體樣式,消除默認(rèn)樣式 */
 body{
 margin:0;
 padding:0;
 }
 #box{
 position:relative;
 width:1000px;
 height:30px;
 margin:100px auto;
 } 
 #progress{
 position:relative;
 width:900px;
 height:30px;
 background:#999999;
 border-radius:8px;
 margin:0 auto; 
 }
 #progress_head{
 width:0px;
 height:100%;
 border-top-left-radius:8px;
 border-bottom-left-radius:8px;
 background:#9933CC;
 
 }
 span{
 position:absolute;
 width:20px;
 height:38px;
 background:#9933CC;
 top:-4px;
 left:0px;
 cursor:pointer;
 }
 #percentage{
 position:absolute;
 line-height:30px;
 text-align:center;
 right:-44px;
 top:0;
 }
 
 
 </style>
</head>
<body>

 <!-- 整體盒子 -->
 <div id="box">
 <!-- 進(jìn)度條整體 -->
 <div id="progress">
 <!-- 進(jìn)度條長度 -->
  <div id="progress_head"></div>
 <!-- 進(jìn)度條移動(dòng)條 -->
 <span id="span"></span>
 <div>
 <!-- 顯示數(shù)據(jù) -->
 <div id="percentage">0%</div>
 </div>

</body>
</html>
<script>

 //js獲取節(jié)點(diǎn)
 var oProgress=document.getElementById('progress');
 var oProgress_head=document.getElementById('progress_head');
 var oSpan=document.getElementById('span');
 var oPercentage=document.getElementById('percentage')

 //添加事件 鼠標(biāo)按下的事件
 oSpan.onmousedown=function(event){
 
 var event=event || window.event;
 var x=event.clientX-oSpan.offsetLeft;

 document.onmousemove=function(){
 
 var event=event || window.event;
 var wX=event.clientX-x;
 
 
 if(wX<0)
 {
  wX=0;
 }else if(wX>=oProgress.offsetWidth-20)
 {
  wX=oProgress.offsetWidth - 20;
 }
 oProgress_head.style.width=wX+'px';
 oSpan.style.left=wX+'px';
 
 oPercentage.innerHTML=parseInt(wX/(oProgress.offsetWidth-20)*100)+'%';
 
 
 return false;
 };
 
 document.onmouseup=function(){
 
 document.onmousemove=null;
 
 };
 
 };
 
</script>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

漾濞| 兴安盟| 铁岭县| 阳信县| 武鸣县| 晋宁县| 靖江市| 新郑市| 广水市| 拜城县| 富顺县| 泊头市| 伊金霍洛旗| 衡水市| 靖州| 壤塘县| 温泉县| 镇康县| 西畴县| 锡林浩特市| 信阳市| 会昌县| 临高县| 武邑县| 渑池县| 廊坊市| 威海市| 嘉峪关市| 黄冈市| 望都县| 丹江口市| 常德市| 富平县| 婺源县| 荔浦县| 定日县| 江油市| 天峨县| 花莲市| 梓潼县| 修水县|