vue滑動tabber居中顯示

1.html

<div class="scroll-title">
   <div class="list" ref="viewBox">
    <ul>
      <li :class="{'select-tab' : tabIndex == classIndex}" v-for="(classItem, classIndex) in productClassList" :key="classIndex" @click="typeClick(classItem.product_class_id, classIndex)">{{classItem.name}}</li>
    </ul>
   </div>
  <div class="line"></div>
  <div class="mine-course-wrap" @click="mineCourse()">我的課程</div>
</div>

2.初始化bar顯示

let that = this;
setTimeout(()=> {
   that.$refs.viewBox.scrollLeft = that.$refs.viewBox.scrollWidth / this.productClassList.length * (that.tabIndex - 1);
}, 500);
this.$refs.viewBox.addEventListener('scroll', this.scroll);

3.點擊事件

scroll() {
   this.scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
},
// 點擊type
typeClick(e, index) {
  this.tabIndex = index;
  store.set({'tab_index': this.tabIndex})
  this.productClassId = e;
  this.getProductListFun(this.productClassId)
  if (index == 0 || index == 1) {
    this.$refs.viewBox.scrollLeft = 0;
  }
  if (index >= 2) {
    this.$refs.viewBox.scrollLeft = this.$refs.viewBox.scrollWidth / this.productClassList.length * (index - 1);
  } 
},

4.css

.scroll-title {
    width: 7rem;
    height: 0.8rem;
    padding: 0 0.25rem; 
    background-color: #FFFFFF;
    position: -webkit-sticky;
    position: sticky;
    top: 0.87rem;
    padding-bottom: 1px; 
    border-bottom: 0.01rem solid #ddd;
  }
  .list {
    width: 5.5rem;
    height: 0.8rem;
    overflow-x: scroll;
    overflow-y: hidden;
    float: left;
    box-sizing: border-box;
    -webkit-overflow-scrolling : touch;
    -ms-overflow-style: none;
    overflow: -moz-scrollbars-none; 
    padding-bottom: 0.9rem;
    ::-webkit-scrollbar { width: 0 !important }
    ul {
      font-size: 0.3rem;
      list-style: none;
      height: 0.8rem;
      line-height: 0.8rem;
      white-space: nowrap;
      li {
        padding: 0 0.2rem;
        display: inline-block;
      }
    }
  }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、通過CocoaPods安裝項目名稱項目信息 AFNetworking網(wǎng)絡(luò)請求組件 FMDB本地數(shù)據(jù)庫組件 SD...
    陽明AI閱讀 16,209評論 3 119
  • 很長一段時間來,我總是會跟不太了解我的人介紹自己說:我的學(xué)業(yè)和事業(yè)相對較順,小學(xué)保送初中,初中保送高中,大學(xué)保送研...
    Vivian愛生活愛分享閱讀 298評論 0 0
  • 站在秋的路口, 依偎秋的懷抱, 看一片落葉渲染了秋色, 看一季落花滄桑了流年。 冷秋、冷晨、 冷霜、冷落葉; 暖情...
    DreamOn_d8cf閱讀 1,551評論 1 3

友情鏈接更多精彩內(nèi)容