數組數據,每行顯示不同顏色


// js
data {
    c: ['red', 'yel', 'gre'],
    s: [],
    list: ['親子關係', '高效學習', '能力培養', '性格塑造', '安全', '教育', '科學膳食', '健康管理', '教育諮詢']
},

mounted () {
  this.$nextTick(() => {
    for (let i = 0; i<this.list.length; i++) {
    // 根據你屏幕距離進行計算--請結合實際情況
      let l = this.$refs.item[i].getBoundingClientRect().left - 220
      if (l === 20) {
        this.s.push(i)
      }
     }
     console.log('s:', this.s)
    })
}


// html
<div class="test">
  <div class="test-item" ref="item" v-for="(item, ci) in list">{{item}}</div>
  <div class="test-show">
     <div v-for="(sitem, si) in s" class="line" :class="c[si]">
         <div v-for="(litem, li) in list" >
         <div class="test-item" v-if="li>=s[si] && li<s[si+1]">{{litem}}</div>
         <div class="test-item" v-if="s[s.length-1]<=li && si===s.length-1">{{litem}}</div>
     </div>
  </div>
  </div>
</div>


// css
.test {
  position: relative;
  width: 375px; height: 667px;background:pink;padding: 40px 20px;
  &-item {
    display: inline-block;
    padding: 7px 8px;
    margin-right: 25px;
    margin-bottom: 10px;
    color: transparent;
  }
  &-show {
    position: absolute;
    top: 40px;
  }
  .line {
    display: flex;
  }
  .red {
    .test-item {
      color: red;
      border: 1px solid red;
    }
  }
  .yel {
    .test-item {
      color: yellow;
      border: 1px solid yellow;
    }
  }
  .gre {
    .test-item {
      color: green;
      border: 1px solid green;
    }
  }
}

可擴展..... 鼠標點擊或者滑過  改變背景顏色 等.....待續......

 

 

 

 

 

 

 

░░░░░░░░░░░░░░░░░░░░與劉大仙戀愛♡♡♡1184天啦~~~~~~~░░░░░░░░░░░░░░░░░░░░

❈❉✿❀ღ❤          一生之中一定會遇到某個人,他打破你的原則,成爲你的例外,成就你全世界的幸福。       ❈❉✿❀ღ❤

                 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章