移动端滑块导航栏

一.效果图

滑动并且下面的滑块跟着动
在这里插入图片描述
1.静态就不多说了在你盒子里面加 overflow-y: auto;超出横线滚动条滑动模块就搞定了
2.下面的滑块
在添加overflow-y: auto的这个盒子添加滚动条事件 @scroll=“scrollEvent($event)”

<div class="box" @scroll="scrollEvent($event)">

获取滚动条便宜距离

const scrollEvent = (e: any) => {
  scrollEve.value = e.srcElement.scrollLeft
  console.log(e.srcElement.scrollLeft)
  // let menuList = that.$refs.menuList
}

计算
scrollEve 获取的偏移量 0.35是我自己这边计算的,我这里是25px到头,所以就25/700大家看情况计算我这里写死了

<div class="load-1" :style="{ left: scrollEve * 0.035 + 'px' }"></div>

完整代码

<template>
  <div class="top fs-18">组合订购享受更多</div>
  <div class="box" @scroll="scrollEvent($event)">
    <div class="box-s flex-d">
      <div
        :style="{ width: 206 * (index + 1) + 'px' }"
        class="box-1"
        v-for="(item, index) in data.dataList"
        :key="index"
        @click="handelOK(item)"
      >
        <div class="box-1-1"><img src="" alt="" /></div>
        <div class="box-1-2 flex-p">
          <span>{{ item.name }}</span>
          <div class="box-1-2-1"><img src="" alt="" /></div>
        </div>
      </div>
    </div>
    <div class="load">
      <div class="load-1" :style="{ left: scrollEve * 0.035 + 'px' }"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'

import { useRouter } from 'vue-router'
const router = useRouter()
const scrollEve = ref(0)
const data = reactive({
  dataList: [
    { name: '韩先生' },
    { name: '韩先生1' },
    { name: '韩先生2' },
    { name: '韩先生3' },
    { name: '韩先生4' },
    { name: '韩先生4' },
    { name: '韩先生4' },
    { name: '韩先生4' },
    { name: '韩先生4' },
    { name: '韩先生5' }
  ]
})
const handelOK = (item: object) => {
  console.log(item)
}

const scrollEvent = (e: any) => {
  scrollEve.value = e.srcElement.scrollLeft
  console.log(e.srcElement.scrollLeft)
  // let menuList = that.$refs.menuList
}
</script>

<style lang="scss" scoped>
$full-width: 206px;
.top {
  color: #333333;
  margin-top: 52px;
}
.flex-d {
  display: flex;
}

.box {
  height: 274px;
  overflow-y: auto;
  margin-top: 28px;
  // background-color: #333333;

  .box-s {
    // width: $full-width * 6;
    .box-1 {
      width: 182px;
      height: 226px;
      position: relative;
      margin: 0 24px 0 0;
      &-1 {
        width: 182px;
        height: 182px;
        background-color: aqua;
        img {
          width: 36px;
          height: 36px;
          background-color: #333333;
          position: absolute;
          right: 19px;
          top: 12px;
        }
      }
      &-2 {
        width: 182px;
        height: 52px;
        border-radius: 24px;
        background-color: #ccc;
        position: absolute;
        bottom: 20px;
        z-index: 1;
        font-size: 26px;
        &-1 {
          width: 40px;
          height: 40px;
          background-color: #333333;
        }
      }
    }
  }
  .load {
    width: 96px;
    height: 8px;
    background-color: #c2c6de;
    border-radius: 24px;
    position: absolute;
    left: 326px;
    display: flex;
    &-1 {
      width: 50px;
      height: 8px;
      border-radius: 24px;
      background-color: #256fff;
      position: absolute;
    }
  }
}
/*滚动条样式*/
::-webkit-scrollbar {
  display: none; /*隐藏滚动条 */
 
}

 
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值