vue使用vue-seamless-scroll自动滚动插件

复制代码
首先运行命令npm install vue-seamless-scroll --save
template:
<div class="publicNotification" @click="toDetail($event)">
      <vue-seamless-scroll :class-option="publicNotificationOption" :data="publicNotification">
        <div v-for="(item, index) in publicNotification" :key="index" style="line-height: 40px;cursor: pointer;">{{item.infoName}}</div>
      </vue-seamless-scroll>
    </div>
复制代码
复制代码
script:
import vueSeamlessScroll from 'vue-seamless-scroll' components: { vueSeamlessScroll }, data() { return { publicNotification: [] } }, computed: { publicNotificationOption() { return { limitMoveNum: 1, // 开始无缝滚动的数据量 hoverStop: true, // 是否开启鼠标悬停stop singleHeight: 40, // 单步运动停止的高度 waitTime: 1500 // 单步运动停止的时间(默认值1000ms) } } }, methods: { toDetail(e) { console.log(e.target.innerHTML) } }
复制代码

toDetail方法写在vue-seamless-scroll中的div中可以获取到整个item对象,但是有一个bug就是第一个item点击没有反应,网上说是因为vue-seamless-scroll中间包裹的dom复制渲染,没有带上dom的事件导致,使用事件委托方法解决,所以方法加在了外边,通过e.target获取。publicNotificationOption中还有很多属性可以设置滚动样式,可以搜索查看下。

posted @   //唉  阅读(650)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示