網(wǎng)站首頁(yè) Vue 正文
<template>
<div class="container">
<div class="wrapper" style="margin-left: 125px;">
<div class="section" style="width:100%"
v-for="(item, index) in list" :key="index">
<div style="width:100%;height:100%;font-size:14px;font-weight:bold;color:#fff;"
:style="{'background':item.backgroundcolor}">
<p style="font-size:18px;font-weight:bold;">{{item.name}}</p>
<div>{{item.text}}</div>
</div>
</div>
</div>
<nav style="position:fixed;left:30px;top:350px;">
<el-tabs @tab-click="handleClick" v-model="activeName"
:tab-position="tabPosition" style="height: 200px;">
<el-tab-pane :name="'tab'+index" :class="index==0?'current':''"
v-for="(item, index) in list" :key="index" :label="item.name">
</el-tab-pane>
</el-tabs>
</nav>
</div>
</template>
<script>
export default {
data(){
return {
activeName:'tab0',
tabPosition:'right',
scroll: '',
list: [{
name: "第一條",
backgroundcolor: "#90B2A3"
}, {
name: "第二條",
backgroundcolor: "#A593B2"
}, {
name: "第三條",
backgroundcolor: "#A7B293"
}, {
name: "第四條",
backgroundcolor: "#0F2798"
}, {
name: "第五條",
backgroundcolor: "#0A464D"
}],
navList: [1, 2, 3, 4, 5]
}
},
methods: {
//這里傳入的tab相當(dāng)于item
handleClick(tab,event){
console.log(tab.index)
this.jump(tab.index)
},
dataScroll: function () {
this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
},
jump(index) {
let jump = document.getElementsByClassName('section');
// 獲取需要滾動(dòng)的距離
let total = jump[index].offsetTop;
// Chrome
document.body.scrollTop = total;
// Firefox
document.documentElement.scrollTop = total;
// Safari
window.pageYOffset = total;
// $('html, body').animate({
// 'scrollTop': total
// }, 400);
},
// 用循環(huán)的方式將每個(gè)標(biāo)題離頂部的距離與滾動(dòng)條當(dāng)前位置對(duì)比來(lái)確定哪個(gè)標(biāo)題需要變?yōu)楦吡? loadScroll: function () {
var self = this;
var sections = document.getElementsByClassName('section');
for (var i = sections.length - 1; i >= 0; i--) {
if (self.scroll >= sections[i].offsetTop - 100) {
//我在上面規(guī)定了每個(gè)el-tab-pane標(biāo)簽的name屬性值為tab+該標(biāo)簽的index值
self.activeName = 'tab'+i
break;
}
}
}
},
watch: {
//監(jiān)聽scroll變量,只要滾動(dòng)條位置變化就會(huì)執(zhí)行方法loadScroll
scroll: function () {
this.loadScroll()
}
},
mounted() {
// scroll代表滾動(dòng)條距離頁(yè)面頂部距離
window.addEventListener('scroll', this.dataScroll);
}
}
</script>
<style lang="scss" scoped>
* {
padding: 0;
margin: 0;
}
.nav1 {
display: block;
width: 120px;
height: 40px;
text-align: left;
line-height: 40px;
color: #fff;
/* background: #eee; */
margin: 10px 0;
cursor: pointer;
padding-left: 18px;
&:hover{
color: #0177ff;
}
}
.current {
color: #0578fc !important;
cursor: pointer;
}
nav{
// border-left: 1px solid #eee;
a{
border-left: 3px solid #0177ff;
}
}
</style>
<style>
.el-tabs__header.is-right{
margin-right: 100px !important;
}
</style>
原文鏈接:https://blog.csdn.net/weixin_38897313/article/details/129896911
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-07-12 微信小程序布局框架初步了解(彈性容器)
- 2022-07-13 復(fù)選框 prop 不觸發(fā) change 事件
- 2022-07-18 CSS基礎(chǔ)語(yǔ)法和盒模型
- 2022-06-10 在vscode中快速新建html文件的2種方法總結(jié)_C 語(yǔ)言
- 2022-07-26 淺談Redis的事件驅(qū)動(dòng)模型_Redis
- 2022-04-20 基于PyQT5制作一個(gè)桌面摸魚工具_(dá)python
- 2021-12-10 k8s部署ingress-nginx的方法步驟_nginx
- 2022-04-17 css absolute絕對(duì)定位 讓 top 和bottom 同時(shí)生效
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支