最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實(shí)現(xiàn)側(cè)邊定位欄

 更新時間:2022年07月15日 16:25:16   作者:什么什么什么?  
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)側(cè)邊定位欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue實(shí)現(xiàn)側(cè)邊定位欄的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)思路:

1.通過點(diǎn)擊側(cè)邊欄,定位到響應(yīng)的內(nèi)容
2.滑動滑動欄,側(cè)邊欄同步高亮對應(yīng)的item

效果圖如下:

1. 通過點(diǎn)擊側(cè)邊欄,定位到響應(yīng)的內(nèi)容

如果是用html的話我們可以用 錨點(diǎn) 的辦法進(jìn)行定位;
在vue中,我們可以通過獲取組件的高度,將滑動欄定位到對應(yīng)的位置

在進(jìn)入主題之前我們需要先了解3個關(guān)于獲取高度的屬性

1.scrollTop 滑動欄中的滑塊離視區(qū)最頂部的距離

document.documentElement.scrollTop || document.body.scrollTop

2.clientHeight 視區(qū)的高度

document.documentElement.clientHeight || document.body.clientHeight

3.scrollHeight 滑動欄里面的滑動塊的高度

document.documentElement.scrollHeight || document.body.scrollHeight

vue中我們可以通過this.$refs.xxx.$el.offsetTop獲取組件距離頁面最頂部的距離,通過賦值給document.documentElement.scrollTop選中組件距離頁面最頂部的高度,控制滑動框滑到頁面對應(yīng)位置。相關(guān)代碼如下:

頁面代碼

// 頁面組件代碼
<div>
? ? <btl-header />
? ? <div class="reports">
? ? ? <side-bar v-bind="sideBarData" />
? ? ? <div class="main">
? ? ? ? <live-overview-part
? ? ? ? ? ref="liveOverview"
? ? ? ? ? :shopNameOptions="allShopName"
? ? ? ? ? :dateSelectorData="dateType_0" />
? ? ? ? <procurenment-alert
? ? ? ? ? ref="procurenmentAlert"
? ? ? ? ? :carBrandOptions="carBrandOptions"
? ? ? ? ? :shopNameOptions="allShopName"
? ? ? ? ? :dateSelectorData="dateType_2" />
? ? ? ? <sales-overview
? ? ? ? ? ref="salesOverview"
? ? ? ? ? :shopNameOptions="allShopName"
? ? ? ? ? :dateSelectorData1="pardsType_0"
? ? ? ? ? :dateSelectorData2="dateType_1" />
? ? ? ? <inquiry-data
? ? ? ? ? ref="inquiryData"
? ? ? ? ? :shopNameOptions="allShopName"
? ? ? ? ? :dateSelectorData="dateType_2" />
? ? ? ? <transaction-data
? ? ? ? ? ref="transactionData"
? ? ? ? ? :carBrandOptions="carBrandOptions"
? ? ? ? ? :shopNameOptions="allShopName"
? ? ? ? ? :qualityOptions="qualityOptions"
? ? ? ? ? :colorSeries="colorSeries"
? ? ? ? ? :dateSelectorData="dateType_2" />
? ? ? </div>
? ? </div>

// ?獲取組件距離頁面頂部高度 ?。?!
?<script>
mounted() {
? ? // ??!注意,需要頁面渲染完才能獲取各個盒子的高度
? ? this.sideBarData.offsetTopliveOverview = this.$refs.liveOverview.$el.offsetTop;
? ? this.sideBarData.offsetTopprocurenmentAlert = this.$refs.procurenmentAlert.$el.offsetTop;
? ? this.sideBarData.offsetTopsalesOverview = this.$refs.salesOverview.$el.offsetTop;
? ? this.sideBarData.offsetTopinquiryData = this.$refs.inquiryData.$el.offsetTop;
? ? this.sideBarData.offsetToptransactionData = this.$refs.transactionData.$el.offsetTop;
? ?},
? </script>

側(cè)邊欄實(shí)現(xiàn)代碼

// 側(cè)邊欄代碼
<template>
? <hn-card class="sidebar">
? ? <ul class="nav-tabs">
? ? ? <li
? ? ? ? class="activeTip"
? ? ? ? ref="activeTip"></li>
? ? ? <li
? ? ? ? @click="clickanchor('liveOverview',0)"
? ? ? ? class="item"
? ? ? ? :class="active==='liveOverview'?'active':'noActive'">實(shí)時總覽</li>
? ? ? <li
? ? ? ? class="item"
? ? ? ? :class="active==='procurenmentAlert'?'active':'noActive'"
? ? ? ? @click="clickanchor('procurenmentAlert',1)">采購預(yù)警</li>
? ? ? <li
? ? ? ? class="item"
? ? ? ? :class="active==='salesOverview'?'active':'noActive'"
? ? ? ? @click="clickanchor('salesOverview',2)">銷售概覽</li>
? ? ? <li
? ? ? ? class="item"
? ? ? ? :class="active==='inquiryData'?'active':'noActive'"
? ? ? ? @click="clickanchor('inquiryData',3)">詢價數(shù)據(jù)</li>
? ? ? <li
? ? ? ? class="item"
? ? ? ? :class="active==='transactionData'?'active':'noActive'"
? ? ? ? @click="clickanchor('transactionData',4)">交易數(shù)據(jù)</li>
? ? ? <li
? ? ? ? class="item"
? ? ? ? :class="active==='top'?'active':'noActive'"
? ? ? ? @click="clickanchor('top')">返回頂部</li>
? ? </ul>
? </hn-card>
</template>

// 側(cè)邊欄js
<script>
methods: {
// 點(diǎn)擊側(cè)邊欄item時觸發(fā)
// 通過document.documentElement.scrollTop控制滑動欄位置
? ? clickanchor(itemName, i) {
? ? ? if (itemName === 'top') {
? ? ? ? document.documentElement.scrollTop = 0; // 滑動欄位置
? ? ? ? this.active = itemName;
? ? ? ? this.$refs.activeTip.style.transform = `translateY(${196}px)`;
? ? ? ? return;
? ? ? }
? ? ? this.$refs.activeTip.style.transform = `translateY(${i * 39}px)`;
? ? ? document.documentElement.scrollTop = this[`offsetTop${itemName}`];
? ? ? this.active = itemName;
? ? },
</script>

2. 滑動滑動欄,側(cè)邊欄同步高亮對應(yīng)的item

通過監(jiān)聽滑動欄滑動,獲取滑動塊距離頁面頂部的高度,和組件距離頁面頂部的高度進(jìn)行對比,反向設(shè)置滑動欄的高亮位置;

// 監(jiān)聽滑動欄滾動,通過監(jiān)聽滾動到的位置,到
? ? scrollChange() {
? ? ? const scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
? ? ? const windowHeight = document.documentElement.clientHeight || document.body.clientHeight || 0;
? ? ? const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight || 0;
? ? ? const allContentOffsettop = [
? ? ? ? 'offsetTopliveOverview',
? ? ? ? 'offsetTopprocurenmentAlert',
? ? ? ? 'offsetTopsalesOverview',
? ? ? ? 'offsetTopinquiryData',
? ? ? ? 'offsetToptransactionData'];
? ? ? if (scrollTop === 0) {
? ? ? ? if (this.active !== 'top') {
? ? ? ? ? this.active = 'top';
? ? ? ? ? this.$refs.activeTip.style.transform = `translateY(${196}px)`;
? ? ? ? }
? ? ? } else if (scrollTop + windowHeight > scrollHeight || scrollTop + windowHeight === scrollHeight) {
? ? ? ? if (this.active !== 'transactionData') {
? ? ? ? ? this.active = 'transactionData';
? ? ? ? ? this.$refs.activeTip.style.transform = `translateY(${157}px)`;
? ? ? ? }
? ? ? } else {
? ? ? ? for (let i = 0; i < allContentOffsettop.length; i++) {
? ? ? ? ? if (this[allContentOffsettop[i]] - 1 > scrollTop) {
? ? ? ? ? ? const contentName = allContentOffsettop[i - 1].replace('offsetTop', '');
? ? ? ? ? ? if (this.active !== contentName) {
? ? ? ? ? ? ? this.active = contentName;
? ? ? ? ? ? ? this.$refs.activeTip.style.transform = `translateY(${(i - 1) * 39}px)`;
? ? ? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? ? }
? ? ? ? }
? ? ? }
? ? },
? },
};

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue3生成隨機(jī)密碼的示例代碼

    vue3生成隨機(jī)密碼的示例代碼

    本文主要介紹了vue3生成隨機(jī)密碼的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • vue 使用 vue-pdf 實(shí)現(xiàn)pdf在線預(yù)覽的示例代碼

    vue 使用 vue-pdf 實(shí)現(xiàn)pdf在線預(yù)覽的示例代碼

    這篇文章主要介紹了vue 使用 vue-pdf 實(shí)現(xiàn)pdf在線預(yù)覽的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • vue封裝自定義分頁器組件與使用方法分享

    vue封裝自定義分頁器組件與使用方法分享

    這篇文章主要給大家介紹了關(guān)于vue封裝自定義分頁器組件與使用方法的相關(guān)資料,非常的好用,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2022-01-01
  • Vue列表渲染的示例代碼

    Vue列表渲染的示例代碼

    這篇文章主要介紹了Vue列表渲染的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • vue-element-admin搭建后臺管理系統(tǒng)的實(shí)現(xiàn)步驟

    vue-element-admin搭建后臺管理系統(tǒng)的實(shí)現(xiàn)步驟

    本文主要介紹了vue-element-admin搭建后臺管理系統(tǒng)的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • vue elementui el-form rules動態(tài)驗(yàn)證的實(shí)例代碼詳解

    vue elementui el-form rules動態(tài)驗(yàn)證的實(shí)例代碼詳解

    在使用elementUI el-form 中,對于業(yè)務(wù)不同的時候可能會產(chǎn)生不同表單結(jié)構(gòu),但是都是存在同一個表單控件el-form中。這篇文章主要介紹了vue elementui el-form rules動態(tài)驗(yàn)證的實(shí)例代碼,需要的朋友可以參考下
    2019-05-05
  • Vue 組件參數(shù)校驗(yàn)與非props特性的方法

    Vue 組件參數(shù)校驗(yàn)與非props特性的方法

    這篇文章主要介紹了Vue 組件參數(shù)校驗(yàn)與非props特性的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02
  • Vue項(xiàng)目中token驗(yàn)證登錄(前端部分)

    Vue項(xiàng)目中token驗(yàn)證登錄(前端部分)

    這篇文章主要為大家詳細(xì)介紹了Vue項(xiàng)目中token驗(yàn)證登錄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • vue中使用AJAX實(shí)現(xiàn)讀取來自XML文件的信息

    vue中使用AJAX實(shí)現(xiàn)讀取來自XML文件的信息

    這篇文章主要為大家詳細(xì)介紹了vue中如何使用AJAX實(shí)現(xiàn)讀取來自XML文件的信息,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,需要的小伙伴可以參考下
    2023-12-12
  • vue?過濾、模糊查詢及計算屬性?computed詳解

    vue?過濾、模糊查詢及計算屬性?computed詳解

    計算屬性是vue里面為了簡化在模板語法中對響應(yīng)式屬性做計算而存在的,這篇文章主要介紹了vue?過濾、模糊查詢(計算屬性?computed),需要的朋友可以參考下
    2022-11-11

最新評論

宁化县| 承德县| 卢湾区| 兰州市| 新邵县| 常山县| 佛山市| 孟连| 松桃| 金川县| 乾安县| 高平市| 松潘县| 南丰县| 新疆| 朝阳区| 会泽县| 罗平县| 南投县| 龙南县| 茶陵县| 信宜市| 射阳县| 迁西县| 濮阳县| 崇明县| 昔阳县| 沙雅县| 南平市| 明溪县| 大姚县| 简阳市| 彭州市| 马尔康县| 万全县| 遂昌县| 东丽区| 哈密市| 佛教| 榆树市| 秀山|