亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue+element-ui監(jiān)聽滾動實現(xiàn)錨點定位方式(雙向),錨點問題

 更新時間:2024年07月24日 09:12:17   作者:波塞西呀  
這篇文章主要介紹了vue+element-ui監(jiān)聽滾動實現(xiàn)錨點定位方式(雙向),錨點問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

vue+element-ui監(jiān)聽滾動實現(xiàn)錨點定位(雙向),錨點問題

雙向綁定錨點問題是最近項目中遇到的一個問題,網(wǎng)上也有很多方法,不過還是想自己記錄一下。

需求 

滾動內(nèi)容為左右布局的右邊內(nèi)容欄內(nèi),內(nèi)容滾動 左邊 定位 右邊內(nèi)容滾動。

話不多說,直接看代碼

注意:class=“d_jump”

<userInfo class="d_jump" ref="d_jump" :userInfo="userInfolists"></userInfo>
 <el-menu
   :default-active="activeName"
   class="hk-person-item"
   text-color="#333"
   mode="horizontal"
   @select="handleSelect()"
   :style="{top: NavDistance + 'px'}"
   >
   <el-menu-item @click="jump(0)" index="1">
     <span >個人信息</span>
   </el-menu-item>
   <el-menu-item @click="jump(1)" index="2">
     <span>求職意向</span>
   </el-menu-item>
   <el-menu-item @click="jump(2)" index="3">
     <span>求職狀態(tài)</span>
   </el-menu-item>
   <el-menu-item @click="jump(3)" index="4">
     <span>教育經(jīng)歷</span>
   </el-menu-item>
   <el-menu-item @click="jump(4)" index="5">
     <span>工作經(jīng)歷</span>
   </el-menu-item>
   <el-menu-item @click="jump(5)" index="6">
     <span>項目經(jīng)歷</span>
   </el-menu-item>
   <el-menu-item @click="jump(6)" index="7">
     <span>我的證書</span>
   </el-menu-item>
 </el-menu>
 <div class="hk-details-bar" id="state" ref="myMenu">
   <div id="resumes" class="hk-details-title"  >
     <jwIntention class="d_jump" ref="d_jump" :jwList="jwList" ></jwIntention>
     <workState class="d_jump" ref="d_jump" :jobWantState="jobWantState"></workState>
     <education class="d_jump" ref="d_jump" :eduLists="educationList"></education>
     <workFor class="d_jump" ref="d_jump" :workList="workList"></workFor>
     <myProject class="d_jump" ref="d_jump" :projectList="projectList"></myProject>
     <myCert class="d_jump" ref="d_jump" :certList="certList"></myCert>
   </div>
data () {
	return {
		activeName: '1',
        isActive: '1',
        scrolls: {},
        NavDistance: 321,
        navStyle: 0,
        scrollHeight: 0,
	}
}

相關(guān)代碼

mounted: function () {
    this.$nextTick(function () {
      window.addEventListener('scroll', this.onScroll)
    })
  },
  methods: {
    handleSelect (key, keyPath) {
      console.log(key, keyPath)
      var index = ''
      index = key
      console.log(index)
      // if (index === '2') {
      // this.$router.push({path: '/front/project'})
      // this.activeName = '3'
      // }
    },
    onScroll () {
      let scrolled = document.documentElement.scrollTop || document.body.scrollTop
      if (scrolled >= 1300) {
        this.activeName = '7'
        console.log('7')
      } else if (scrolled < 60 && scrolled >= 0) {
        this.activeName = '1'
        console.log('1')
      } else if (scrolled < 150 && scrolled >= 60) {
        this.activeName = '2'
        console.log('2')
      } else if (scrolled < 200 && scrolled >= 100) {
        this.activeName = '3'
        console.log('3')
      } else if (scrolled < 600 && scrolled >= 500) {
        this.activeName = '4'
        console.log('4')
      } else if (scrolled < 700 && scrolled >= 600) {
        this.activeName = '5'
        console.log('5')
      } else if (scrolled < 800 && scrolled >= 700) {
        this.activeName = '6'
        console.log('6')
      }
    },
    onScrollBehavior (index) {
    },
    // 錨點實驗
    jump (index) {
      console.log(index)
      let active = index.toString()
      this.isActive = active
      // 判斷導航高度
      // myMenu
      let height = this.$refs.myMenu.offsetHeight
      // 用 class="d_jump" 添加錨點
      let jump = window.document.querySelectorAll('.d_jump')
      let total = jump[index].offsetTop
      console.log(total)
      let distance = document.documentElement.scrollTop || document.body.scrollTop
      // 平滑滾動,時長500ms,每10ms一跳,共50跳
      let step = total / 50
      // 判斷小導航距離頂部的位置
      let newDistance = this.NavDistance
      if (index === 0 && newDistance < total) {
        newDistance = 321
      } else if (index > 0 || index <= 6) {
        this.NavDistance = total
      } else {
        this.NavDistance = total - 600
      }

      if (total > distance) {
        smoothDown()
      } else {
        let newTotal = distance - total
        step = newTotal / 50
        smoothUp()
      }
      function smoothDown () {
        if (distance < total) {
          distance += step
          document.body.scrollTop = distance
          document.documentElement.scrollTop = distance
          setTimeout(smoothDown, 10)
        } else {
          document.body.scrollTop = total
          document.documentElement.scrollTop = total
        }
      }
      function smoothUp () {
        if (distance > total) {
          distance -= step
          document.body.scrollTop = distance
          document.documentElement.scrollTop = distance
          setTimeout(smoothUp, 10)
        } else {
          document.body.scrollTop = total
          document.documentElement.scrollTop = total
        }
      }
    }
  },
  watch: {
    activeName: function () {
      console.log(this.activeName)
    }
  }

element步驟條增加錨點的實現(xiàn)

element的步驟條默認樣式是無法點擊的,需求中有點擊步驟條,頁面滾動到特定錨點需求

實現(xiàn)如下:

 <el-card shadow="never" :body-style="{ padding: '5px' }"  id="mySteps">
            <el-steps simple>
              <el-step v-for="(step,index) in laSteps" :title="step.title" :icon="step.icon"
                       :key="index"
                       :href="step.href" rel="external nofollow"  :status="step.status" v-if="step.isShow"></el-step>
            </el-steps>
          </el-card>

1.每個步驟條中 :href=“step.href” 錨點是通過一個href與一個id實現(xiàn)跳轉(zhuǎn),這里的href僅僅作為一種標識與需要跳轉(zhuǎn)的點id相同即可

   $('.el-step__title').click(function () {
        var goHref = '#' + $(this).parent().parent().attr('href')
        var anchor = that.$el.querySelector(goHref)
        $('#djla').animate({
          scrollTop: anchor.offsetTop
        }, 500);
      });

2.獲取到href的值,根據(jù)這個值決定跳轉(zhuǎn)到什么地方.

3.$(’#djla’)為jq選中整個需滾動區(qū)域

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 15分鐘學會vue項目改造成SSR(小白教程)

    15分鐘學會vue項目改造成SSR(小白教程)

    這篇文章主要介紹了15分鐘學會vue項目改造成SSR(小白教程),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • 基于Element-Ui封裝公共表格組件的詳細圖文步驟

    基于Element-Ui封裝公共表格組件的詳細圖文步驟

    在平時開發(fā)的時候很多情況都會使用到表格和分頁功能,下面這篇文章主要給大家介紹了關(guān)于如何基于Element-Ui封裝公共表格組件的詳細圖文步驟,需要的朋友可以參考下
    2022-09-09
  • Vue和SpringBoot之間傳遞時間的方法實現(xiàn)

    Vue和SpringBoot之間傳遞時間的方法實現(xiàn)

    本文主要介紹了Vue和SpringBoot之間傳遞時間的方法實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-07-07
  • Vue.js 的移動端組件庫mint-ui實現(xiàn)無限滾動加載更多的方法

    Vue.js 的移動端組件庫mint-ui實現(xiàn)無限滾動加載更多的方法

    下面小編就為大家分享一篇Vue.js 的移動端組件庫mint-ui實現(xiàn)無限滾動加載更多的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • vite項目無法使用zangodb包裝器的解決方案

    vite項目無法使用zangodb包裝器的解決方案

    vite作為新一代工具鏈,具有很多便利之處,配置也非常簡單,它很好地整合了Rollup和其他復雜的構(gòu)建項,并提供了多種方向的典型腳手架模板,深受大家喜愛,本文給大家介紹了如何解決vite項目無法使用zangodb包裝器的問題,需要的朋友可以參考下
    2023-10-10
  • vue3 響應式對象如何實現(xiàn)方法的不同點

    vue3 響應式對象如何實現(xiàn)方法的不同點

    這篇文章主要介紹了vue3 響應式對象如何實現(xiàn)方法的不同點,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • vue實現(xiàn)圖片滑動驗證

    vue實現(xiàn)圖片滑動驗證

    這篇文章主要為大家詳細介紹了vue實現(xiàn)圖片滑動驗證,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Vue如何基于vue-i18n實現(xiàn)多國語言兼容

    Vue如何基于vue-i18n實現(xiàn)多國語言兼容

    這篇文章主要介紹了Vue如何基于vue-i18n實現(xiàn)多國語言兼容,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-07-07
  • vue父元素點擊事件與子元素點擊事件沖突問題

    vue父元素點擊事件與子元素點擊事件沖突問題

    這篇文章主要介紹了vue父元素點擊事件與子元素點擊事件沖突問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Vue3響應式對象是如何實現(xiàn)的(1)

    Vue3響應式對象是如何實現(xiàn)的(1)

    這篇文章主要介紹了Vue3響應式對象是如何實現(xiàn)的,文章圍繞主題展開詳細的內(nèi)容介紹具有一定的參考價值,需要的小伙伴可以參考一下
    2022-08-08

最新評論