tab超出部分点击展开和收起动画

<template>
  <!-- 大于55个(包含全部和未分配时增加滚动条,不然页面会很长) -->
  <div class="tabsContainer flex-none" ref="tabsContainer" :class="{ wrap: staffList.length > 55 }">
    <scroll ref="scrollContainer" v-if="!isWrap" direction="horizontal" class="tabsScroll">
      <tabs class="tabs" :tabArr="staffList" :activeTab.sync="activeTabScroll" :isWrap="isWrap" @click="tabsClick">
        <div slot="collapse" class="collapse-box" @touchstart="btnEnter" @touchend="btnleave" @click="wrapChange">
          <i class="iconfont icon-sanjiaoxing up"></i>
        </div>
      </tabs>
    </scroll>
    <div v-else>
      <tabs class="tabs" :tabArr="staffList" :activeTab.sync="activeTabScroll" :isWrap="isWrap" @click="tabsClick">
        <div slot="collapse" class="collapse-box" @touchstart="btnEnter" @touchend="btnleave" @click="wrapChange">
          <i class="iconfont icon-sanjiaoxing up"></i>
        </div>
      </tabs>
    </div>
    <div class="collapse-box" @touchstart="btnEnter" @touchend="btnleave" v-if="!isWrap && staffList.length >= 5" @click="wrapChange">
      <i class="iconfont icon-sanjiaoxing"></i>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
import { BtnHover } from '@mixin/common.js'
import Scroll from '@base/scroll/scroll.vue'
import Tabs from './tabsIsWrap'
export default {
  name: 'selectBox',
  components: {
    Scroll,
    Tabs
  },
  mixins: [BtnHover],
  props: {
    staffList: {
      type: Array,
      default: ()=>[]
    }
  },
  data() {
    return {
      isWrap: false,
      activeTabScroll: 0,
      height: 3.3
    }
  },
  watch: {
    isWrap() {
      this.scrollChange()
    },
    activeTabScroll() {
      if(this.isWrap){
        this.scrollChange()
      }
    }
  },
  methods: {
    initClick() {
      this.activeTabScroll = 0
      this.isWrap = false
      this.wrapperHeightChange()
    },
    scrollChange() {
      this.$nextTick(()=>{
        if(this.$refs.scrollContainer) {
          this.$refs.scrollContainer.initScroll()
          let ele = document.querySelector(".tabs").firstChild.childNodes[this.activeTabScroll + 1]
          this.$refs.scrollContainer.scrollToElement(ele, 0, 0, 0)
        }
      })
    },
    tabsClick(item, index) {
      this.$emit('click', item, index)
    },
    wrapChange() {
      this.isWrap = !this.isWrap
      this.wrapperHeightChange()
    },
    wrapperHeightChange() {
      const el = this.$refs.tabsContainer
      const dataLength = this.staffList.length
      if (this.isWrap) {
        if (dataLength <= 4) {
          el.style.height = '3.3rem'
        } else {
          // el.style.height = Math.ceil(dataLength / 4) * 3.3 + 'rem'
          if(this.height === 3.3) {
            el.style.height = 'auto'
            this.$nextTick(()=>{
              this.height = el.offsetHeight / 10
              el.style.height = this.height + 'rem'
              console.log(el.offsetHeight)
            })
          } else {
            el.style.height = this.height + 'rem'
          }
        }
      } else {
        el.style.height = '3.3rem'
      }
    }
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
.tabsContainer
  background #fff
  margin 0.4rem 0.4rem 0rem
  padding 0 0 0 1.2rem
  border-radius 0.5rem
  position relative
  display flex
  overflow hidden
  max-height calc(100% - 7.5rem - 3.3rem - 4.6rem - 3.7rem - 5.4rem)
  transition height 0.3s ease-in-out
  height 3.3rem
  &.wrap
    overflow auto
  .tabsScroll
    >>>
      .scroll-content
        min-width 100%
        display inline-block
        vertical-align top
  .collapse-box
    display flex
    align-items center
    justify-content center
    width 3.3rem
    height 3.3rem
    box-shadow -5px 0px 10px -4px rgba(153, 153, 153, 0.2)
    z-index 2
    .iconfont
      font-size 1rem
      color #999
      display inline-block
      transform scale(0.42)
      &.up
        transform rotate(-180deg) scale(0.42)
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在Vue中实现tab切换可以使用多种方法。其中一种方法是使用v-show指令控制内容的显示和隐藏。通过点事件改变一个变量的值作为开关,从而控制tab样式和内容的显示和隐藏。这个方法简单易懂,适用于少量tab的情况。另一种方法是使用组件切换。在Vue中可以使用is特性和keep-alive组件来实现组件的缓存。通过在router-view组件外部包裹一个keep-alive组件,并设置include属性为当前活跃的标签页组件的name属性,就可以实现标签页组件的缓存。当切换标签页时,缓存的组件状态会被保留。另外一种方法是使用路由切换。通过使用router-link组件来实现标签页之间的切换。这种方法对地址栏和数据请求比较友好,适用于需要进行路由导航的情况。在实现标签页切换时,可以结合使用上述方法中的keep-alive组件来实现组件的缓存,从而提升性能。 [2 [3<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [vue中如何实现tab切换功能?](https://blog.csdn.net/weixin_57550930/article/details/120541115)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [vue tab切换,echarts组件不刷新](https://blog.csdn.net/weixin_46943039/article/details/122720812)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

King_960725

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值