日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

滑動列表數據按照A-Z首字母排列,右邊A-Z能動態定位到相應字母位置

作者:沙漠藍色披頭 更新時間: 2022-01-17 編程語言

核心實現,循環右邊字母列表,然后找出左邊數據列表,對應id為相應字母的元素,計算元素到頂部和底部的距離,就是范圍,然后滑動監聽,通過滑動的距離在哪個范圍確定右邊要定位到哪個字母,實現最終效果:

this.$nextTick(() => {
        this.itemsParent = []
        for (let i = 0; i < this.listforgirht.length; i++) {
          const height = document.getElementById(this.listforgirht[i]).offsetHeight
          const top = document.getElementById(this.listforgirht[i]).offsetTop
          var items = { tag: '', topInstance: '', bottomInstance: '', position: '' }
          if (i === 1) {
            this.$set(items, 'tag', this.listforgirht[i])
            this.$set(items, 'topInstance', 0)
            this.$set(items, 'bottomInstance', height)
            this.$set(items, 'position', i)
          }
          this.$set(items, 'tag', this.listforgirht[i])
          this.$set(items, 'topInstance', top)
          this.$set(items, 'bottomInstance', top + height)
          this.$set(items, 'position', i)
          this.itemsParent.push(items)
        }
        console.log(this.itemsParent)
      })
    },
    scrollListen (event) {
      const top = event.target.scrollTop
      for (const item6 of this.itemsParent) {
        if (top >= item6.topInstance && top <= item6.bottomInstance) {
          const pos = item6.position
          this.indexm = pos
          console.log(pos)

          return
        }
      }
      console.log(event.target.scrollTop)

      console.log('123456')
    }

原文鏈接:https://blog.csdn.net/u013075460/article/details/120343496

欄目分類
最近更新