PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > JavaScript教程 > 正文

    js控制的滑动进度条

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:js控制的滑动进度条
    js控制的滑动进度条

    1. <!doctype html> 
    2. <html> 
    3. <head> 
    4.    <script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script> 
    5.     <script type="text/javascript"
    6.         $(document).ready(function (e) { 
    7.             //设置最大值 
    8.             ScrollBar.maxValue = 100; 
    9.             //初始化 
    10.             ScrollBar.Initialize(); 
    11.             //设置最大值 
    12.             ProgressBar.maxValue = 100; 
    13.             //设置当前刻度 
    14.             var index = 0; 
    15.             var mProgressTimer = setInterval(function () { 
    16.                 index += 2; 
    17.                 ProgressBar.SetValue(index); 
    18.             }, 100); 
    19.  
    20.         }); 
    21.         var ScrollBar = { 
    22.             value: 20, 
    23.             maxValue: 100, 
    24.             step: 1, 
    25.             currentX: 0, 
    26.             Initialize: function () { 
    27.                 if (this.value > this.maxValue) { 
    28.                     alert("给定当前值大于了最大值"); 
    29.                     return
    30.                 } 
    31.                 this.GetValue(); 
    32.                 $("#scroll_Track").css("width"this.currentX + 2 + "px"); 
    33.                 $("#scroll_Thumb").css("margin-left"this.currentX + "px"); 
    34.                 this.Value(); 
    35.                 $("#scrollBarTxt").html(ScrollBar.value + "/" + ScrollBar.maxValue); 
    36.             }, 
    37.             Value: function () { 
    38.                 var valite = false
    39.                 var currentValue; 
    40.                 $("#scroll_Thumb").mousedown(function () { 
    41.                     valite = true
    42.                     $(document.body).mousemove(function (event) { 
    43.                         if (valite == falsereturn
    44.                         var changeX = event.clientX - ScrollBar.currentX; 
    45.                         currentValue = changeX - ScrollBar.currentX - $("#Demo").offset().left; 
    46.                         $("#scroll_Thumb").css("margin-left", currentValue + "px"); 
    47.                         $("#scroll_Track").css("width", currentValue + 2 + "px"); 
    48.                         if ((currentValue + 25) >= $("#scrollBar").width()) { 
    49.                             $("#scroll_Thumb").css("margin-left", $("#scrollBar").width() - 25 + "px"); 
    50.                             $("#scroll_Track").css("width", $("#scrollBar").width() + 2 + "px"); 
    51.                             ScrollBar.value = ScrollBar.maxValue; 
    52.                         } else if (currentValue <= 0) { 
    53.                             $("#scroll_Thumb").css("margin-left""0px"); 
    54.                             $("#scroll_Track").css("width""0px"); 
    55.                         } else { 
    56.                             ScrollBar.value = Math.round(100 * (currentValue / $("#scrollBar").width())); 
    57.                         } 
    58.                         $("#scrollBarTxt").html(ScrollBar.value + "/" + ScrollBar.maxValue); 
    59.                     }); 
    60.                 }); 
    61.                 $(document.body).mouseup(function () { 
    62.                     ScrollBar.value = Math.round(100 * (currentValue / $("#scrollBar").width())); 
    63.                     valite = false
    64.                     if (ScrollBar.value >= ScrollBar.maxValue) ScrollBar.value = ScrollBar.maxValue; 
    65.                     if (ScrollBar.value <= 0) ScrollBar.value = 0; 
    66.                     $("#scrollBarTxt").html(ScrollBar.value + "/" + ScrollBar.maxValue); 
    67.                 }); 
    68.             }, 
    69.             GetValue: function () { 
    70.                 this.currentX = $("#scrollBar").width() * (this.value / this.maxValue); 
    71.             } 
    72.         } 
    73.         var ProgressBar = { 
    74.             maxValue: 100, 
    75.             value: 20, 
    76.             SetValue: function (aValue) { 
    77.                 this.value = aValue; 
    78.                 if (this.value >= this.maxValue) this.value = this.maxValue; 
    79.                 if (this.value <= 0) this.value = 0; 
    80.                 var mWidth = this.value / this.maxValue * $("#progressBar").width() + "px"
    81.                 $("#progressBar_Track").css("width", mWidth); 
    82.                 $("#progressBarTxt").html(this.value + "/" + this.maxValue); 
    83.             } 
    84.         } 
    85.     </script> 
    86. <style type="text/css"
    87. #Main { 
    88.     width: 70%; 
    89.     height: 300px; 
    90.     margin: 0 auto; 
    91.     margin-top: 10px; 
    92. #scrollBar { 
    93.     width: 80%; 
    94.     height: 10px; 
    95.     background-color: #ccc; 
    96.     margin: 0 auto; 
    97.     margin-top: 50px; 
    98.     -webkit-border-radius: 2em; 
    99.     -moz-border-radius: 2em; 
    100.     border-radius: 2em; 
    101.     cursor: pointer; 
    102. #scroll_Track { 
    103.     width: 0px; 
    104.     height: 10px; 
    105.     background-color: #ff4400; 
    106.     -webkit-border-radius: 2em; 
    107.     -moz-border-radius: 2em; 
    108.     border-radius: 2em; 
    109. #scroll_Thumb { 
    110.     height: 25px; 
    111.     width: 25px; 
    112.     background-color: #efefef; 
    113.     -webkit-border-radius: 2em; 
    114.     -moz-border-radius: 2em; 
    115.     border-radius: 2em; 
    116.     border: 1px solid #ccc; 
    117.     -webkit-box-shadow: 0px 0px 5px #ccc; 
    118.     -moz-box-shadow: 0px 0px 5px #ccc; 
    119.     box-shadow: 0px 0px 5px #ccc; 
    120.     position: absolute; 
    121.     margin-top: -18px; 
    122.     cursor: pointer; 
    123. #scroll_Thumb:hover { 
    124.     background-color: #ff4400; 
    125.     border: 1px solid #fff; 
    126. #progressBar { 
    127.     width: 80%; 
    128.     height: 10px; 
    129.     background-color: #ccc; 
    130.     margin: 0 auto; 
    131.     margin-top: 50px; 
    132.     -webkit-border-radius: 2em; 
    133.     -moz-border-radius: 2em; 
    134.     border-radius: 2em; 
    135. #progressBar_Track { 
    136.     width: 200px; 
    137.     height: 10px; 
    138.     background-color: #ff4400; 
    139.     -webkit-border-radius: 2em; 
    140.     -moz-border-radius: 2em; 
    141.     border-radius: 2em; 
    142. #beian { 
    143.     text-align: center; 
    144.     float: left; 
    145.     width: 100%; 
    146.     margin-top: 50px 
    147. #beian a { 
    148.     color: gray; 
    149.     font: 13px "微软雅黑", Arial, Helvetica, sans-serif; 
    150.  
    151.  .progressTime { 
    152.             filter: alpha(opacity=50); 
    153.             -moz-opacity: 0.5; 
    154.             -khtml-opacity: 0.5; 
    155.             opacity: 0.5; 
    156.             position: absolute; 
    157.             _position: fixed; 
    158.             left: 25%; 
    159.             top:25%; 
    160.             Z-INDEX: 2; 
    161.             border: 1px solid gray; 
    162.             -moz-border-radius: 5px; 
    163.             -webkit-border-radius: 5px; 
    164.             border-radius: 5px; 
    165.             color: white; 
    166.             background: #000; 
    167.             width: 660px; 
    168.             height:200px; 
    169.             padding-top: 0px; 
    170.             padding-bottom: 0px; 
    171.         } 
    172. </style> 
    173. </head> 
    174. <body> 
    175.  
    176.  
    177.  
    178.      
    179.  
    180.       <div id="Demo" class="progressTime" > 
    181.         <div id="Main"
    182.           <div id="scrollBar"
    183.             <div id="scroll_Track"></div> 
    184.             <div id="scroll_Thumb"></div> 
    185.           </div> 
    186.           <p id="scrollBarTxt" style="text-align:center;"></p> 
    187.           <div id="progressBar"
    188.             <div id="progressBar_Track"></div> 
    189.           </div> 
    190.           <p id="progressBarTxt" style="text-align:center;"></p> 
    191.         </div> 
    192.        
    193.       </div> 
    194.  
    195. </body> 
    196.  
    197. </html> 

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-69-3647-1.html
    相关热词搜索: js进度条