ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

移动端托拽进度条

2021-10-13 17:34:44  阅读:128  来源: 互联网

标签:scale 进度条 title background 端托 var position 移动 left


<!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>

标签:scale,进度条,title,background,端托,var,position,移动,left
来源: https://blog.csdn.net/lin_jiejie/article/details/120748564

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有