菜单左右滑动

在这里插入图片描述
效果如图所示

"vue-seamless-scroll": "^1.1.23", 安装该组件
 <div class="wrapper menu" ref="wrapper">
      <ul ref="content" class="content">
        <li class="activate">
          <i>首页</i>
          <div>首页</div>
        </li>
        <li
          v-for="(item, index) in menuList"
          :key="index"
          @click="menuSkip(item.name)"
        >
          <i>{{ item.meta.title }}</i>
          <div>{{ item.meta.title }}</div>
        </li>
      </ul>
      <div v-if="opac" class="opac">首页</div>
    </div>

    import BScroll from "better-scroll"; //引入该组件
    initScroll() {
      // 给内层盒子设置宽度,不设置宽度的话无法滚动

      let len = this.menuList.length + 1;
      let allWidth = 0;
      for (let i = 0; i < len; i++) {
        let liWidth = this.$refs.content.children[i].offsetWidth;
        allWidth += liWidth;
      }
      // 如果有外边距,可以这样写。需要去掉最后一个元素的外边距,在后面减一下
      // let width = this.goodslength * (60 + 10) - 10
      this.$refs.content.style.width = allWidth + 10 + 80 + "px"; //10 :放大的宽度,80是右边遮罩的宽度
      if (allWidth + 10 > this.$refs.wrapper.offsetWidth) {
        this.opac = true;
      } else {
        this.opac = false;
      }
      this.$nextTick(() => {
        if (!this.Scroll) {
          this.Scroll = new BScroll(this.$refs.wrapper, {
            click: true, // 配置允许点击事件
            scrollX: true, // 开启横向滚动
            eventPassthrough: "vertical", // 当设置 eventPassthrough 为 'vertical' 的时候,scrollY 无效
          });
        } else {
          this.Scroll.refresh(); // 重新计算 better-scroll,当 DOM 结构发生变化的时确保滚动效果正常
        }
      });
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值