滾動到指定位置

    //滾動到選中定位的位置
    selectedRegion() {
      // 通過Id獲取到對應的dom元素
      const node = document.getElementById(this.sertCurrnetKey)

      setTimeout(() => {
        if (node) {
          this.$nextTick(() => {
            // 通過scrollIntoView方法將對應的dom元素定位到可見區域 【block: 'center'】這個屬性是在垂直方向居中顯示
            node.scrollIntoView({
              behavior: 'smooth', // 平滑過渡 值有auto、instant,smooth,緩動動畫(當前是慢速的)
              block: 'center',
            })
          })
        }
      }, 100)
    },

  

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