移動端自訂美觀的滑動條

來源:互聯網
上載者:User

標籤:進度條、移動端進度條、自訂滑動條、滑動條、h5滑動條

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/8D/08/wKioL1iDLBmD213eAAAGLzbDBnE070.png-wh_500x0-wm_3-wmp_4-s_2351492165.png" title="2017-01-21_173802.png" alt="wKioL1iDLBmD213eAAAGLzbDBnE070.png-wh_50" />

html部分:

<!--進度條 S-->
                    <div class="m_i_c_con">
                        <div id="dragOut" class="m_i_c_out"><div id="dragBar" class="m_i_c_in"></div></div>
                        <div id="dragBtn" class="m_i_c_drag">0%</div>
                    </div>
<!--進度條 E-->

css部分:

.m_i_c_con{ position: relative; height: 55px; }
.m_i_c_out{ position: absolute; overflow: hidden; left: -1px; top:8px; box-shadow: 0 1px 1px #e3e3e3; width: 100%; height: 12px; border: 1px solid #e7e7e7; border-radius:5px; background-color: #fff;}
.m_i_c_in{ height: 18px; width: 0%; background-color: #C1C1C1;}
.m_i_c_drag{position: absolute; z-index: 100; left: 0%; top: 0px; width: 46px; height: 56px; margin-left: -8%; line-height: 76px; background: url(../images/tuodongqiu.png) no-repeat center 0px; background-size: 26px; text-align: center;color: #8a8b8b; font-size: 15px;}

Js部分:

$(function(){
              var opts = {};
              $(‘#dragBtn‘).bind(‘touchstart‘,function(e){
                  e.preventDefault();
                  opts.startX = e.originalEvent.changedTouches[0].pageX;
                  opts.offsetLeft = parseFloat($(this).css(‘left‘));
              });
              
              $(‘#dragBtn‘).bind(‘touchmove‘,function(e){
                  e.preventDefault();
                  opts.moveEndX = e.originalEvent.changedTouches[0].pageX;
               opts.X = opts.moveEndX - opts.startX;
               
               opts.full = parseFloat($(‘#dragOut‘).width());
               opts.newLeft = opts.X + opts.offsetLeft;
               opts.perval = opts.newLeft / opts.full * 100;
               
               if(opts.newLeft <= opts.full && opts.newLeft >= 0){
                       $(‘#dragBar‘).width(opts.perval.toFixed(0) + ‘%‘);
                       $(this).css({‘left‘:opts.perval.toFixed(0) + ‘%‘});                  
                       $(this).text(opts.perval.toFixed(0) + ‘%‘);
               }
              });
              
              $(‘#dragBtn‘).bind(‘touchend‘,function(e){

                     e.preventDefault();
                  opts = {};
              });


移動端自訂美觀的滑動條

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.