当前位置:   article > 正文

解决vue中使用vue-seamless-scroll插件无缝滚动点击事件失效问题_vue-seamless-scroll实现点击效果不起作用

vue-seamless-scroll实现点击效果不起作用

 

需求:使用vue-seamless-scroll插件实现列表无缝滚动,也可以添加相应的点击跳转,点击事件会存在点击失效的问题。支持上下左右无缝滚动,单步滚动停留时间,以及水平方向的手动切换。

效果图:

无缝滚动

 

基于vue的无缝滚动组件

注意:需要给父容器一个height:data='Array'overfolw:hidden;左右滚动需要给ul容器一个初始化 css width。 

参考配置:

向下滚动 direction:0

向下滚动 direction:1

向左滚动 direction:2

向右滚动 direction:3

鼠标悬停关闭 hoverStop:false

单行停顿 singleHeight:26

单行停顿时间 singleHeight:26 waitTime:2500

 1、安装

npm install vue-seamless-scroll --save

2、引入使用

  • 局部 页面使用:

import vueSeamlessScroll from "vue-seamless-scroll";
 components: {
    vueSeamlessScroll,
  },
 data(){
     return {
         bbsData:[]
    }
},
computed: {
    bbsOption () {
        return {
            step: 0.2, // 数值越大速度滚动越快
            limitMoveNum: 3, // 开始无缝滚动的数据量 this.bbsData.length
            hoverStop: false, // 是否开启鼠标悬停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)
        }
    }
}

  •  全局main.js引入:
  1. import vueSeamlessScroll from 'vue-seamless-scroll'
  2. Vue.use(vueSeamlessScroll)

主要代码: 

bbsData是接口获取的数据绑定,根据自己绑定定义。

  1. <div class="three-info mt40 bbsInfo" v-if="bbsData.length>0" @click.stop="handleBBs($event)">
  2. <vue-seamless-scroll :data="bbsData" :class-option="bbsOption" >
  3. <ul class="ul-scoll">
  4. <li v-for="item in bbsData" :key='item.topicId' class="info-item flex align-items">
  5. <div class=" fontSize20 info-tag mr10 bbs-tag">论坛</div>
  6. <div class=" fontSize26 color3 van-ellipsis" style="flex:1" :data-id="item.topicId">{{item.topicTitle}}</div>
  7. </li>
  8. </ul>
  9. </vue-seamless-scroll>
  10. </div>
  1. .three-info{
  2. padding:0 20px 20px;
  3. border-radius: 10px;
  4. }
  5. .info-item{
  6. padding-bottom:20px;
  7. padding-top:20px;
  8. border-bottom:1px solid #F1F6F8;
  9. }
  10. .info-item .info-tag{
  11. width: 62px;
  12. padding:6px 10px;
  13. background: #3E91FF;
  14. color:#fff;
  15. text-align: center;
  16. border-radius: 6px;
  17. }
  18. .bbsInfo{
  19. background:#FEFBE8;
  20. height:264px;
  21. overflow: hidden;
  22. }
  23. .info-item .bbs-tag{
  24. background:#FAAF3D;
  25. }

 解决点击事件失效问题办法:

可以携带参数,注意要在代码中自定义

<div class=" fontSize26 color3 van-ellipsis" style="flex:1" :data-id="item.topicId">{{item.topicTitle}}</div>

获取自定义属性id,当然也可以自定义其他的属性

target.dataset.id

 判断当前的节点是否是DIV,可以写其他的,对应获取tagName

  1. handleBBs(e){
  2. let target = e.target;
  3. if(target.tagName == "DIV") {
  4. this.$router.push({
  5. path:"/forum/forumDetail",
  6. query:{topicId:target.dataset.id}
  7. });
  8. }
  9. }

 

发文不易,点赞、收藏、评论、关注一下呗! 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/903965
推荐阅读
相关标签
  

闽ICP备14008679号