15年软件开发经验 只做源码定制 互联网+定制化解决方案

15年软件开发经验,只做源码定制!

原创设计 定制开发

满足您的个性化需求

当前位置:首页 前端开发 H5

移动端进度条

苗成龙| 发布于 2021-10-20 19:31:31| 655阅读| 0点赞| 0评论
举报

移动端进度条 可以左右拖拉 。

使用jquery来实现一个简单的移动端可拖拽进度条

先引入jquery

<script src="js/jquery-1.10.2.min.js">script>

在创建样式

html 

<ul class="lanren">
        <li><span id="title">0span>
            <div class="scale_panel">
                <span class="f-left">0span>
                <span class="f-right">100span>
                <div class="scale" id="bar">
                    <div>div>
                    <span id="btn">span>
                div>
            div>
        li>
    ul>

css

   ul.lanren {
            margin: 100px auto;
        }
        
        .scale_panel {
            color: #999;
            position: absolute;
            line-height: 18px;
            left: 60px;
            top: -0px;
        }
        
        .scale_panel>span:first-child {
            position: absolute;
            left: -5rem;
            font-size: 2rem;
        }
        
        .scale_panel>span:nth-child(2) {
            position: absolute;
            right: -5rem;
            font-size: 2rem;
        }
        
        .scale>span {
            background-color: red;
            width: 3rem;
            height: 3rem;
            position: absolute;
            left: -2px;
            top: -15px;
            cursor: pointer;
            border-radius: 50%;
            font-size: 2rem;
        }
        
        .scale {
            background-repeat: repeat-x;
            background-position: 0 100%;
            background-image: linear-gradient(to right, #08D7F2 0%, #2BF06A 50%, #2BF06A 50%, #FC6076 100%);
            border-left: 1px #83BBD9 solid;
            width: 43rem;
            height: 1rem;
            position: relative;
            border-radius: 2rem;
        }
        
        .scale>div {
            background-repeat: repeat-x;
            background-color: red;
            /*进度条颜色*/
            width: 0px;
            position: absolute;
            height: 1rem;
            width: 0;
            left: 0;
            bottom: 0;
            border-radius: 2rem;
        }
        
        .lanren>li {
            margin-left: 3.5rem;
            position: relative;
            list-style: none;
            font-size: 3rem;
        }
        
        #title {
            position: absolute;
            top: -6rem;
            left: 23rem;
        }

写jquery来实现

<script>
    // 进度条代码
    var 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.ontouchstart = function(e) {
                var x = (e || b.event).touches[0].clientX;
                var l = this.offsetLeft;
                var max = f.bar.offsetWidth - this.offsetWidth;
                g.ontouchmove = function(e) {
                    var thisX = (e || b.event).touches[0].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.ontouchend = new Function('this.onmousemove=null');
            };
        },
        ondrag: function(pos, x) {
            this.step.style.width = Math.max(0, x) + 'px';
            this.title.innerHTML = pos + '%';
        }
    }
    new scale('btn', 'bar', 'title');
script>
0

0条评论

别默默看啦~登录/注册一起参与讨论吧~

热门标签

苗成龙
微信扫一扫立即咨询
账号登录|扫码登录

立即注册 |忘记密码?

欢迎注册

已有账号马上登录

重置密码

扫码绑定微信
微信扫一扫

绑定手机号

分享到-微信

举报

  • 举报类型:

  • 举报描述:

您好,当前积分不足。

在线客服
拨打电话
17330196230 13230981129
顶部