移动端滑动条(原生JS)

Posted dontes

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了移动端滑动条(原生JS)相关的知识,希望对你有一定的参考价值。

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>干货-课程-完成</title>
    <style>
    ul.lanren{
        margin:40px auto;

    }
    .scale_panel{
        color:#999;
        position:absolute;
        line-height:18px;
        left:60px;top:-0px;
    }
    .scale_panel>span:first-child{
        position: absolute;
        left: -50px;
        font-size: 20px;
    }
    .scale_panel>span:nth-child(2){
        position: absolute;
        right: -50px;
        font-size: 20px;
    }
    .scale>span{
        background-color: red;
        width:30px;
        height:30px;
        position:absolute;
        left:-2px;top:-15px;
        cursor:pointer;
        border-radius: 50%;
        font-size: 20px;
    }
    .scale{
        background-color: #eee;
        border-left: 1px #83BBD9 solid; 
        width: 430px; 
        height: 10px; 
        position: relative; 
        border-radius: 20px; 
    }
    .scale>div{ 
        background-repeat: repeat-x; 
        background-color: red; /*进度条颜色*/
        width: 0px; 
        position: absolute; 
        height: 10px; 
        width: 0; left: 0; bottom: 0; 
        border-radius: 20px;
    }
    .lanren>li{
        margin-left: 3.50px;
        position:relative;
        list-style:none;
        font-size: 30px;
    }
    #title{
        position: absolute;
        top: 20px;
        left: 30px;
    }
</style>
</head>
<body>
    <!-- 可拖拽进度条 -->
    <ul class="lanren">
        <li><span id="title">0</span>
            <div class="scale_panel">
                <div class="scale" id="bar">
                    <div></div>
                    <span id="btn"></span>
                </div>
            </div>
        </li>
    </ul>
    <script src="../lib/[email protected]@hash"></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.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>
</body>
</html>

 

以上是关于移动端滑动条(原生JS)的主要内容,如果未能解决你的问题,请参考以下文章

ios移动端原生滚动条滚动不灵敏问题

ios移动端原生滚动条滚动不灵敏问题

移动端原生js,css3实现轮播图

原生js移动端可拖动进度条插件

用matlabGUI界面读取图片,滑动滚动条来调节图像亮度,用imadd函数,代码一直出错,急,求高手帮忙

使用原生js封装webapp滑动效果(惯性滑动滑动回弹)