1、效果图
2、步骤
(1)引入插件
import vueSeamless from 'vue-seamless-scroll'
(2)注册组件
components: {vueSeamless},
(3)html使用
<div style=" height: 86%; padding:10px;margin: 0 auto;">
<vue-seamless :data="dataList" :class-option="classOption" style=" height: 100%;overflow: hidden;">
<div>
<div v-for="item in dataList" >
<div>
<div style="width:50%;height: 100%;float: left;padding: 2px 5px;">
<div style=" color: #00ffc6;">
<span>{{ item.optTime }}</span>
</div>
</div>
<div style="width:20%;height: 100%;float: left;padding: 2px 5px;">
<div style="color: #00ffc6;">
<span>{{ item.orgName }}</span>
</div>
</div>
<div style="width:30%;height: 100%;float: left;padding: 2px 5px;">
<div style="color: #00ffc6;">
<span>{{ item.optResult }}</span>
</div>
</div>
<!-- <div class="clear"></div>-->
</div>
</div>
</div>
</vue-seamless>
</div>
(4)computed
// 监听属性 类似于data概念
computed: {
defaultOption () {
return {
step: 0.5, // 数值越大速度滚动越快
limitMoveNum: 2, // 开始无缝滚动的数据量 this.dataList.length
hoverStop: true, // 是否开启鼠标悬停stop
direction: 1, // 0向下 1向上 2向左 3向右
openWatch: true, // 开启数据实时监控刷新dom
singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
}
}
},
(5)data
dataList:[{optTime:'2021',orgName:'cdscd',optResult:'cdeeeeeeeeeeeeeee'},
{optTime:'2021',orgName:'cdscd',optResult:'cdeeeeeeeeeeeeeee'},
{optTime:'2021',orgName:'cdscd',optResult:'cdeeeeeeeeeeeeeee'},
{optTime:'2021',orgName:'cdscd',optResult:'cdeeeeeeeeeeeeeee'},
{optTime:'2021',orgName:'cdscd',optResult:'cdeeeeeeeeeeeeeee'},
{optTime:'2021',orgName:'cdscd',optResult:'cdeeeeeeeeeeeeeee'}],
3、如果需要对滚动数据操作(实现点击方法)
@click=“handleClick($event)”//使用这个方法即可,可加在需要加的地方
如果需要自定义传参
:data-id=“index” :data-index=“item.name” //自定义要传参的内容
(1)html
<div style=" height: 86%; padding:10px;margin: 0 auto;" @click="handleClick($event)">
<vue-seamless :data="dataList" :class-option="classOption" style=" height: 100%;overflow: hidden;">
<div>
<div v-for="(item,i) in dataList" >
<div>
<div style="width:50%;height: 100%;float: left;padding: 2px 5px;">
<div style=" color: #00ffc6;">
<span :data-id="i" :data-index="item.optTime">{{ item.optTime }}</span>
</div>
</div>
<div style="width:20%;height: 100%;float: left;padding: 2px 5px;">
<div style="color: #00ffc6;">
<span>{{ item.orgName }}</span>
</div>
</div>
<div style="width:30%;height: 100%;float: left;padding: 2px 5px;">
<div style="color: #00ffc6;">
<span>{{ item.optResult }}</span>
</div>
</div>
<!-- <div class="clear"></div>-->
</div>
</div>
</div>
</vue-seamless>
</div>
(2)methods
handleClick(event){
console.log(event)
console.log(event.target)
let id= event.target.dataset.id //自定义的内容必须用dataset获取到
let name= event.target.dataset.index
console.log(id)
console.log(name)
},