BetterScroll 是一款重点解决移动端各种滚动场景需求的开源插件(GitHub地址),适用于滚动列表、选择器、轮播图、索引列表、开屏引导等应用场景。
为了满足这些场景,它不仅支持惯性滚动、边界回弹、滚动条淡入淡出等效果的灵活配置,让滚动更加流畅,同时还提供了很多 API 方法和事件,以便我们更快地实现滚动场景下的需求,如下拉刷新、上拉加载。
由于它基于原生 JavaScript 实现,不依赖任何框架,所以既可以原生 JavaScript 引用,也可以与目前前端 MVVM 框架结合使用,比如,其官网上的示例就是与 Vue 的结合。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| <template> <div class="list" ref='wrapper'> <div> <div class="area"> <div class="title border-topbottom">当前城市</div> <div class="button-list"> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> </div> </div>
<div class="area"> <div class="title border-topbottom">热门城市</div> <div class="button-list"> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button ">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> <div class="button-wrapper"> <div class="button">北京</div> </div> </div> </div>
<div class="area"> <div class="title border-topbottom">A</div> <div class="item-list"> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> </div> </div> <div class="area"> <div class="title border-topbottom">A</div> <div class="item-list"> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> </div> </div> <div class="area"> <div class="title border-topbottom">A</div> <div class="item-list"> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> </div> </div> <div class="area"> <div class="title border-topbottom">A</div> <div class="item-list"> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> </div> </div> <div class="area"> <div class="title border-topbottom">A</div> <div class="item-list"> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> <div class="item border-bottom">甘谷</div> </div> </div>
</div> </div> </template>
<script> import BScroll from 'better-scroll' export default { name: "List", mounted () { this.scroll=new BScroll(this.$refs.wrapper) } } </script>
<style lang="stylus" scoped> .border-topbottom &:befoer border-color #ccc &:after border-color #ccc
.border-bottom &:befoer border-color #ccc
.list position absolute overflow hidden top 1.52rem left 0 right 0 bottom 0 .title text-align left line-height .44rem background #eee padding-left .26rem color #666 .button-list padding .1rem overflow hidden padding .1rem .6rem .1rem .button-wrapper width 33.33% float left .button margin .1rem text-align center border .02rem solid #ccc .item-list text-align left .item line-height .76rem color #666 padding-left .2rem </style>
|