1.安裝
npm install vue-seamless-scroll --save
2.注冊組件
// (1)全局 在main.js中 import Vue from 'vue' import scroll from 'vue-seamless-scroll' Vue.use(scroll)
// (2)單個.vue文件局部注冊 <script> import vueSeamlessScroll from 'vue-seamless-scroll' export default { components: { vueSeamlessScroll } }
3.使用組件
<template> <vue-seamless-scroll :data="listData" class="warp"> <ul class="item"> <li v-for="(item, index) in listData" :key="index"> <span class="title" v-text="item.title"></span> <span class="date" v-text="item.date"></span> </li> </ul> </vue-seamless-scroll> </template> <script> import vueSeamlessScroll from 'vue-seamless-scroll' export default { name: 'Example01Basic', components: { vueSeamlessScroll }, data () { return { listData: [{ 'title': '無縫滾動第一行無縫滾動第一行', 'date': '2017-12-16' }, { 'title': '無縫滾動第二行無縫滾動第二行', 'date': '2017-12-16' }, { 'title': '無縫滾動第三行無縫滾動第三行', 'date': '2017-12-16' }, { 'title': '無縫滾動第四行無縫滾動第四行', 'date': '2017-12-16' }, { 'title': '無縫滾動第五行無縫滾動第五行', 'date': '2017-12-16' }, { 'title': '無縫滾動第六行無縫滾動第六行', 'date': '2017-12-16' }, { 'title': '無縫滾動第七行無縫滾動第七行', 'date': '2017-12-16' }, { 'title': '無縫滾動第八行無縫滾動第八行', 'date': '2017-12-16' }, { 'title': '無縫滾動第九行無縫滾動第九行', 'date': '2017-12-16' }], } }, } </script> <style lang="less" scoped> .warp { height: 270px; width: 360px; margin: 0 auto; overflow: hidden; ul { list-style: none; padding: 0; margin: 0 auto; li, a { display: block; height: 30px; line-height: 30px; display: flex; justify-content: space-between; font-size: 15px; } } } </style>
4.配置項
(1)滾動方向
classOption: { direction: 0 //0向下 1向上 2向左 3向右 }
(2)滾動速度
classOption: {
step: 2, //數值越大速度滾動越快 默認為1
}
(3)鼠標懸停
classOption: { hoverStop: false //鼠標移入之后不停止,,默認停止為true }
(4)單步停頓 singleWidth (direction為2,3) / singleHeight (direction為0,1)
classOption: {
direction: 0
singleHeight: 30 //默認值是0,不停頓 },
(5)停頓時間 waitTime
classOption: { direction: 0, // 滾動方向 2向左 3向右 默認向上 1 0 向下 singleHeight: 30, //單步停頓 waitTime:5000 },
(6)開啟無縫滾動的數據量 limitMoveN
(7)是否自動播放使用switch切換時候需要置為false autoPlay
(8)移動端開啟touch滑動,默認為true openTouch
(9)左右切換按鈕距離左右邊界的距離 switchOffset
(10)手動單步切換step的值 switchSingleStep
(11)單步切換的動畫時間 switchDelay