美文网首页
新学的滚动条的一种写法

新学的滚动条的一种写法

作者: fz_log | 来源:发表于2018-12-20 15:56 被阅读0次
    图片盗用

    html:

    <div class="progress">
                        <div class="progress-bar progress-bar-info progress-bar-striped active" style="width: 85%;">
                            <div class="progress-value">85%</div>
                        </div>
                    </div>
    

    css:

    @keyframes progress-bar-stripes {
        from {
            background-position: 40px 0
        }
    
        to {
            background-position: 0 0
        }
    }
    
    .progress {
        height: 20px;
        margin-bottom: 20px;
        overflow: hidden;
        background-color: #f5f5f5;
        border-radius: 4px;
        -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1);
        box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1)
    }
    
    .progress-bar {
        float: left;
        width: 0;
        height: 100%;
        font-size: 12px;
        line-height: 20px;
        color: #fff;
        text-align: center;
        background-color: #337ab7;
        -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
        box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
        -webkit-transition: width .6s ease;
        -o-transition: width .6s ease;
        transition: width .6s ease
    }
    
    .progress-striped .progress-bar,
    .progress-bar-striped {
        background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
        background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
        background-image: linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
        -webkit-background-size: 40px 40px;
        background-size: 40px 40px        // 这里的背景图size要设置,主要是为了在滚动条的宽度增加时,滚动条的每一个单元条不会随着被拉伸,通过自己写的对比出来的重要性
    }
    
    .progress.active .progress-bar,
    .progress-bar.active {
        -webkit-animation: progress-bar-stripes 2s linear infinite;
        -o-animation: progress-bar-stripes 2s linear infinite;
        animation: progress-bar-stripes 2s linear infinite
    }
    

    其实这是bootstrop中的css写法,可以学习一下

    background-image: linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
    -webkit-background-size: 40px 40px;
    background-size: 40px 40px
    

    主要值得注意的两点:
    1、background-image是滚动条样式的实现
    2、size要设置

    相关文章

      网友评论

          本文标题:新学的滚动条的一种写法

          本文链接:https://www.haomeiwen.com/subject/vewykqtx.html