1.vue3-seamless-scroll
安装
bash
yarn add vue3-seamless-scroll
组件配置
- list
无缝滚动列表数据,组件内部使用列表长度。
ts
type: Array
required: true
- v-model
通过 v-model 控制动画滚动与停止,默认开始滚动
ts
type: Boolean,
default: true,
required: false
- direction
控制滚动方向,可选值
up,down,left,right
ts
type: String,
default: "up",
required: false
- isWatch
开启数据更新监听
ts
type: Boolean,
default: true,
required: false
- hover
是否开启鼠标悬停
ts
type: Boolean,
default: false,
required: false
- count
动画循环次数,默认无限循环
ts
type: Number,
default: "infinite",
required: false
- limitScrollNum
开启滚动的数据量,只有列表长度大于等于该值才会滚动
ts
type: Number,
default: 5,
required: false
- step
步进速度
ts
type: Number,
required: false
- singleHeight
单步运动停止的高度
ts
type: Number,
default: 0,
required: false
- singleWidth
单步运动停止的宽度
ts
type: Number,
default: 0,
required: false
- singleWaitTime
单步停止等待时间(默认值 1000ms)
ts
type: Number,
default: 1000,
required: false
- isRemUnit
singleHeight and singleWidth 是否开启 rem 度量
ts
type: Boolean,
default: true,
required: false
- delay
动画延时时间
shell
type: Number,
default: 0,
required: false
- ease
动画效果,可以传入贝塞尔曲线数值
ts
type: String | cubic-bezier,
default: "ease-in",
required: false
- copyNum
拷贝列表次数,默认拷贝一次,当父级高度大于列表渲染高度的两倍时可以通过该参数控制拷贝列表次数达到无缝滚动效果
ts
type: Number,
default: 1,
required: false
- wheel
在开启鼠标悬停的情况下是否开启滚轮滚动,默认不开启
ts
type: boolean,
default: false,
required: false
- singleLine
启用单行横向滚动
ts
type: boolean,
default: false,
required: false
注意事项
需要滚动的列表所在容器必须设置样式 overflow: hidden;
2.使用
- 全局注册
typescript
/**
* main.ts 全局注册
*/
import { createApp } from 'vue'
import App from './App.vue'
import vue3SeamlessScroll from 'vue3-seamless-scroll'
const app = createApp(App)
app.use(vue3SeamlessScroll)
app.mount('#app')
- 局部注册
vue
<script>
import { defineComponent } from 'vue'
import { Vue3SeamlessScroll } from 'vue3-seamless-scroll'
export default defineComponent({
components: {
Vue3SeamlessScroll
}
})
</script>
点击查看
vue
<script setup lang="ts">
import { ref } from 'vue'
// import { Vue3SeamlessScroll } from 'vue3-seamless-scroll'
const value = ref(true)
const list = ref([
{
title: 'Vue3.0 无缝滚动组件展示数据第1条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第2条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第3条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第4条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第5条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第6条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第7条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第8条',
date: Date.now()
},
{
title: 'Vue3.0 无缝滚动组件展示数据第9条',
date: Date.now()
}
])
</script>
<template>
<a-button type="primary" @click="value = !value">
{{ value ? 'STOP' : 'START' }}
</a-button>
<vue3-seamless-scroll v-model="value" class="scroll" :list="list" hover>
<div v-for="(item, index) in list" :key="index" class="item">
<span>{{ item.title }}</span>
<span>{{ item.date }}</span>
</div>
</vue3-seamless-scroll>
</template>
<style scoped>
.scroll {
height: 270px;
width: 500px;
margin: 0 auto;
overflow: hidden;
}
.scroll .item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 3px 0;
}
</style>