vue横向无缝滚动以及点击按钮切换

插件官网:https://chenxuan0000.github.io/vue-seamless-scroll/zh/guide/01-basic.html

  1. 引入vue-seamless-scroll

npm

npm install vue-seamless-scroll --save

yarn

yarn add vue-seamless-scroll
  1. 在main.js文件里面引入使用

import scroll from 'vue-seamless-scroll'
Vue.use(scroll)
  1. 页面配置

<vue-seamless-scroll :data="data" :class-option="optionSwitch" class="seamless-warp3">
   <span v-if="data.length > 4" slot="left-switch" class="left-arrow"></span>
   <span v-if="data.length > 4" slot="right-switch" class="right-arrow"></span>
   <ul class="item" :style="`width:${455 * (data.length + 1)}px`">
      <li v-for="(item, index) in data" :key="index">
           //需要轮播的组件或者数据
          <parameter :data="item" :title="item[0].bak1"></parameter>
       </li>
    </ul>
</vue-seamless-scroll>

computed配置

 computed: {
    optionSwitch2: {
      get() {
        return {
          navigation: true,//左右方向的滚动是否显示控制器按钮
          switchSingleStep: 450,//点击切换移动的 step 值(px)
          direction: 3,//方向: 0 往下 1 往上 2 向左 3 向右。
          switchOffset: 10,//左右切换按钮距离左右边界的边距(px)。
        }
      }
    }
  },
  1. css

.seamless-warp3 {
  pointer-events: auto;
  overflow: hidden;
  // height: 140px;
  // width: 453px * 4;
  width: 1891px;
  margin: 0 auto;

  .left-arrow,
  .right-arrow {
    position: relative;
    display: inline-block;
    width: 26px;
    height: 113px;
    border-radius: 50%;
    background-color: #00a0e9;
    cursor: pointer;

    // &:hover {
    //   background-color: #0f39fa;
    // }
    &::before {
      position: absolute;
      content: '';
      width: 16px;
      height: 16px;
      top: 12px;
      left: 15px;
      border: 2px solid #fff;
    }
  }

//左右切换按钮的样式
  .left-arrow {
    background: url('../images/right-arrow.png') no-repeat;
  }

  .right-arrow {
    background: url('../images/left-arrow.png') no-repeat;
  }

  .left-arrow::before {
    display: none;
  }

  .right-arrow::before {
    display: none;
  }

  ul,
  li {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  ul.item {
    display: flex;
    align-items: flex-end;

    li {
      height: auto;
    }
  }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值