CSS scroll snap points 实现渐进加强的滚动

前言

前几天在 segmentfault 上看到有人问下面这个效果(segmentfault app 中的)怎么实现,感受这个效果体验还不错(在移动端没有滚动条的状况可以提示有更多内容能够滚动),就用 overflow-x: auto + width: 80% 在 codepen 上写了个 demo。css

segmentfault app 你可能感兴趣的文章

渐近加强

恰好最近看到这篇文章 Introducing CSS Scroll Snap Points ,若是结合 Scroll snap points 每次滚动的时候每一个条目始终在中间这样效果就更好了。<!-- more -->html

.snap-slider {
    overflow-x: auto;
    
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: mandatory;

  scroll-snap-destination: 50% 0;
    &__scroller {
        display: table;
        text-align: center;
    }
    &__item {
        scroll-snap-coordinate: 50% 0%;
        
        display: table-cell;
        line-height: 150px; font-size: 2em;
        
        &:not(:first-child) {
            border-left: 1px solid #ccc;
        }
    }
    &__width {
        width: 80vw;
    }
}

属性的具体介绍,参考本文最后的参考连接。git

效果以下:github

css scroll snap points

查看 Demoweb

浏览器支持状况

遗憾的是目前(7/9/2016)只有 Firefox 和 iOS 上的 Safari 和 Chrome 原生支持(须要前缀),好在这种能够当作渐进加强,即便浏览器不支持也不影响功能。segmentfault

PS:这里有个 polyfill,可是本例中加了彷佛不起做用。浏览器

参考

原文地址:https://uedsky.com/2016-07/css-scroll-snap-points/
获取最佳阅读体验并参与讨论,请访问原文

相关文章
相关标签/搜索