Vue学习笔记:vue-seamless-scroll滚动插件的使用

一、安装

npm install vue-seamless-scroll –save

二、在main.ts中全局挂载

import vueSeamlessScroll from 'vue-seamless-scroll'
Vue.use(vueSeamlessScroll)

三、在要使用该插件的子组件中引入

import vueSeamlessScroll from "vue-seamless-scroll";
@Component({
  components: {
    vueSeamlessScroll,
  },
})

 先执行

npm install @types/vue-seamless-scroll

若npm报错,执行失败,则在src文件中找到type.d.ts文件,进行声明

declare module 'vue-seamless-scroll';

之后就不会再有爆红的情况了

四、使用vue-seamless-scroll

<template>

    <div class="box">
        <vue-seamless-scroll :data="CardPartsStatisticsList" class="seamless-warp" :class-option="classOption">
            <div class="box">
                <ul class="col-list-box" ref="listScroll"  >
                    <li v-for="(item,index) in CardPartsStatisticsList" :key="index"><span>{{item.text}}</span></li>
                </ul>
            </div>

        </vue-seamless-scroll>
    </div>

</template>

<script>
    import vueSeamlessScroll from 'vue-seamless-scroll'
    export default {
        data() {
           return {
               CardPartsStatisticsList:[
                   {text:'1案件编号:J3201445455455444 XX涉案物品24小时未入库,请及时入库'},
                   {text:'2案件编号:Z3201445455455444 XX涉案物品24小时未入库,请及时入库'},
                   {text:'3案件编号:B3201445455455444 XX涉案物品24小时未入库,请及时入库'},
                   {text:'4案件编号:W3201445455455444 XX涉案物品24小时未入库,请及时入库'},
                   {text:'5案件编号:A3201445455455444 XX涉案物品24小时未入库,请及时入库'},
                   {text:'6案件编号:S3201445455455444 XX涉案物品24小时未入库,请及时入库'},
                   {text:'7案件编号:V3201445455455444 XX涉案物品24小时未入库,请及时入库'},
               ]
           }
        },
        components: {    //组件
            vueSeamlessScroll
        },
        computed: {

            classOption () {
                return {
                    step: 0.2, // 数值越大速度滚动越快
                    limitMoveNum: 5, // 开始无缝滚动的数据量 this.dataList.length
                    hoverStop: true, // 是否开启鼠标悬停stop
                    direction: 0, // 0向下 1向上 2向左 3向右
                    openWatch: true, // 开启数据实时监控刷新dom
                    singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
                    singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
                    waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
                }
            }
        },
    }


</script>


<style>
    .box{
        width: 100%;
        height: 400px;
        overflow: hidden;
    }
    .seamless-warp{
        width: 100%;
        height: calc(100% - 16px);
        overflow: hidden;

    }
    .box{
        width: 100%;
        height:400px;
        overflow: hidden;
    }
    .col-list-box{
        width: 100%;
    }
    .col-list-box li{
        width: 588px;
        height: 74px;
        color: #ffffff;
        font-size: 15px;
        margin-top: 20px;
    }

    .col-list-box li:nth-of-type(5n+1){
        background: url("~@/assets/img/col-list1.png") no-repeat;
    }
    .col-list-box li:nth-of-type(5n+2){
        background: url("~@/assets/img/col-list2.png") no-repeat;
    }
    .col-list-box li:nth-of-type(5n+3){
        background: url("~@/assets/img/col-list3.png") no-repeat;
    }
    .col-list-box li:nth-of-type(5n+4){
        background: url("~@/assets/img/col-list4.png") no-repeat;
    }
    .col-list-box li:nth-of-type(5n+5){
        background: url("~@/assets/img/col-list5.png") no-repeat;
    }

    .col-list-box li span{
        float: left;
        width: calc(100% - 87px);
        height: 40px;
        margin: 18px 20px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
</style>

五、效果


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端互助会

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值