移动端托拽进度条

<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>托拽进度条</title>
        <style>
            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;
            }
        </style>
    </head>

    <body>
        <!-- 可拖拽进度条 -->
        <ul class="lanren">
            <li><span id="title">0</span>
                <div class="scale_panel">
                    <span class="f-left">吃力</span>
                    <span class="f-right">轻松</span>
                    <div class="scale" id="bar">
                        <div></div>
                        <span id="btn"></span>
                    </div>
                </div>
            </li>
        </ul>
        <script src="js/jquery-1.10.2.min.js"></script>
        <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.ο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>
    </body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值