下载插件
npm install --save better-scroll
html
<div class="scrollbox">
<ul class="scrollbody"></ul>
</div>
css
容器的高度一定要小于滚动内容的高度
.scrollbox{
height: 500px;
overflow: hidden;//不能是auto或者scroll
position: relative;//防止滚动条出现在容器外
}
.scrollbody{
height: 5000px;
}
js:
//第一个参数为操作对象,第二个参数表示需要滚动条及配置
mounted(){
new BetterScroll('.scrollbox',{
scrollbar:{
fade:true,
interactive:false //1.8.0新增
}
})
}