实现效果:
1.下载插件
npm install vue-seamless-scroll --save
或者
yarn add vue-seamless-scroll
2.实现代码
<template>
<div id="app">
<vue-seamless-scroll
:data="listData"
:class-option="classOption"
class="warp"
>
<div class="img-content">
<div v-for="(item, index) in listData" :key="index" class="img-item">
<img :src="item" alt=""/>
<span>{{ index }}</span>
</div>
</div>
</vue-seamless-scroll>
</div>
</template>
<script>
import vueSeamlessScroll from "vue-seamless-scroll";
export default {
name: 'App',
components: {
vueSeamlessScroll
},
data(){
return {
selectValue:'',
listData: [
'https://img01.yzcdn.cn/vant/apple-1.jpg',
'https://img01.yzcdn.cn/vant/apple-2.jpg',
'https://img01.yzcdn.cn/vant/apple-1.jpg',
'https://img01.yzcdn.cn/vant/apple-2.jpg',
'https://img01.yzcdn.cn/vant/apple-1.jpg',
'https://img01.yzcdn.cn/vant/apple-2.jpg',
],
classOption: {
direction: 2,//滚动方向、0向下 1向上 2向左 3向右
step: 0.5, // 数值越大速度滚动越快
hoverStop: false, // 是否开启鼠标悬停stop
// limitMoveNum: 3, // 开始无缝滚动的数据量 this.dataList.length
// openWatch: true, // 开启数据实时监控刷新dom
// singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
// singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
// waitTime: 0, // 单步运动停止的时间(默认值1000ms)
}
}
}
}
</script>
<style>
#app {
margin-top: 60px;
}
.warp {
width: 500px;
height: 155px;
margin: 0 auto;
overflow: hidden;
border: 2px solid #000;
}
.warp .img-content {
display: flex;
}
.warp .img-item{
width: 120px;
margin-right: 20px;
border:1px solid gray;
}
.warp .img-item img{
width: 100px;
height: 150px;
}
</style>