Vue advanced: El steps to achieve intra page navigation

No Silver Bullet 2020-11-13 07:25:38
vue advanced el steps achieve


In front end development , When the page content is divided into several columns , It is a good user experience to locate the corresponding column by adding navigation fields .

It can be done by el-steps Realize the column jump in the page .el-steps The basic usage is as follows :

<el-steps :active="active" finish-status="success">
<el-step title=" step 1"></el-step>
<el-step title=" step 2"></el-step>
<el-step title=" step 3"></el-step>
</el-steps>
<el-button style="margin-top:12px;" @click="next"> next step </el-button>
data:{

active:0
},
methods:{

next(){

if(this.active++ >2){

this.active = 0
}
}
}

Emphasis on the el-steps Of direction、space、active、process-status、align-center attribute , The screenshot is as follows :
 Insert picture description here

By looking at Element manual , When a step bar of fixed width is needed , Set up space Attribute is enough , Unit is px, If not set to adaptive ( If you are not sure of the height or width of each step in the step bar , Can be set to adaptive ; To make the interface beautiful , Modifiable el-step attribute

.el-step__main {

width: 100%!important;
padding-left: 3%!important;
margin-bottom: 3%!important;
}


el-step The properties are shown in the following figure :
 Insert picture description here

This article focuses on how to apply el-steps Show the information you need dynamically .demo as follows :

<div>
<el-steps direction="vertical" :align-center="true" :active="arr.length" finish-status="success">
<el-step :title="item.title" :description="item.description" v-for="(item, index) in arr" :key="index" @click.native="onCLick(index)">
<template slot="description">
<!-- Form content -->
</template>
</el-step>
</el-steps>
</div>
<div>
<transition name="slide-fade">
<div v-if="shownav" class="rightList">
<span class="line_prev"></span>
<ul>
<li v-for="(item, index) in navArr" :key="index" @click="crollTo(index)" :class="{active: active====index}">
<img src="cue.png" v-if="active === index">
</li>
</ul>
<span class="line_next"></span>
</div>
</transition>
</div>

The above is just to realize the dynamic display of the content of the step bar , If you need to locate the navigation column according to the user's browsing content or quickly locate the relevant column according to the navigation column , Need to achieve through dynamic monitoring page content .


<!-- Process flow processing node navigation field -->
<div v-if="flowopinoin.length > 4" :class="[flowopinoin.length > 10 ? 'navConst' : 'nav']">
<div :class="[flowopinoin.length > 10 ? 'navStyleConst' : 'navStyle']">
<transition name="slide-fade">
<div v-if="shownav" class="rightList">
<span class="line_prev"></span>
<ul>
<li v-for="(item, index) in flowopinoin" :key="index" @click="scrollTo(index)" :class="{active: active===index}">
<img src="../../../assets/img/cur.png" width="20" v-if="active === index"/>
<span>{
{
item.nodename}}</span>
</li>
</ul>
<span class="line_next"></span>
</div>
</transition>
</div>
<el-button @click="shownav = !shownav" type="primary" :class="[flowopinoin.length > 10 ? 'shownavConst' : 'shownav']">
<i style="margin-left: -6px;" :class="[shownav ? 'el-icon-d-arrow-right': 'el-icon-d-arrow-left']"></i>
</el-button>
</div>
this.$nextTick(() => {

// Listen for rolling events
window.addEventListener('scroll', this.onScroll, false)
})
// Scroll monitor
onScroll () {

// Get all anchor elements
const navContents = document.querySelectorAll('.el-steps>.el-step')
// console.log('navContents:', navContents)
// Of all anchor elements offsetTop
const offsetTopArr = []
for (let i = 0; i < navContents.length; i++) {

offsetTopArr.push(navContents[i].offsetTop)
}
// navContents.forEach(item => {

// offsetTopArr.push(item.offsetTop)
// })
// Gets the current document stream's scrollTop
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
// Define the currently lit navigation subscript
for (let n = 0; n < offsetTopArr.length; n++) {

// If scrollTop Greater than or equal to n An element of offsetTop shows n-1 It's completely invisible
// Then the navigation index should be n 了
// console.log('scrollTop:', scrollTop)
// console.log('offsetTopArr[n]:', offsetTopArr[n])
if (scrollTop >= offsetTopArr[n]) {

this.navIndex = n
}
}
this.active = this.navIndex
},
// Jump to the element of the specified index
scrollTo (index) {

// Get the target offsetTop
// css The selector is from 1 Start counting , We are from 0 Start , So we need to +1
const targetOffsetTop = document.querySelector(`.el-steps>.el-step:nth-child(${
index + 1})`).offsetTop
// Get current offsetTop
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop
// Define a jump 50 Pixel , The bigger the number, the faster it jumps , But there will be a sense of falling frames , If you take a big step, you will pull the egg
const STEP = 50
// Judge whether to slide down or up
// console.log('scrollTop:', scrollTop)
// console.log('targetOffsetTop:', targetOffsetTop)
if (scrollTop >= targetOffsetTop) {

// Slide up
smoothUp()
} else {

// Slide down
smoothDown()
}
// Define the slide down function
function smoothDown () {

// If at present scrollTop Less than targetOffsetTop Indicates that the viewport has not yet slid to the specified position
if (scrollTop < targetOffsetTop) {

// If the distance from the target is greater than or equal to STEP Just jump STEP
// Or jump to the target , The goal is to prevent skipping .
if (targetOffsetTop - scrollTop >= STEP) {

scrollTop += STEP
} else {

scrollTop = targetOffsetTop
}
document.body.scrollTop = scrollTop
document.documentElement.scrollTop = scrollTop
// About requestAnimationFrame You can check it by yourself , In this case , comparison setInterval Higher cost performance
requestAnimationFrame(smoothDown)
}
}
// Define a sliding function
function smoothUp () {

if (scrollTop > targetOffsetTop) {

if (scrollTop - targetOffsetTop >= STEP) {

scrollTop -= STEP
} else {

scrollTop = targetOffsetTop
}
document.body.scrollTop = scrollTop
document.documentElement.scrollTop = scrollTop
requestAnimationFrame(smoothUp)
}
}
}
@charset "UTF-8";
.navConst {

position:fixed;
right: 3%;
top:15%;
}
.nav {

position:fixed;
right: 2%;
top:15%;
}
.navStyleConst {

position:fixed;
top:15%;
cursor: pointer;
right: 3%;
width: 7%;
height: auto;
max-height:800px;
overflow: scroll;
overflow-x: hidden;
}
.navStyle {

position:fixed;
top:51%;
cursor: pointer;
right: 2%;
width: 7%;
height: auto;
}
.shownavConst {

position:absolute;
right: -37px;
top: 50%;
width: 10px;
height: 100px;
}
.shownav {

position: fixed;
right:18px;
top: 57%;
}
.shownav2 {

position: fixed;
right:18px;
top: 38%;
}
ul {

list-style: none;
}
.active img {

position: absolute;
left: -26px;
top: 5px;
z-index: 2;
}
.line_prev{

display:inline-block;
width: 1px;
height:20px;
background:#ccc;
position:relative;
left:20px;
bottom:-8px;
}
.line_prev:before{

content: '';
position:absolute;
width:9px;
height:9px;
border-radius:50%;
border:2px solid #EDEDED;
z-index:1;
left:-4px;
top:-8px;
}
.rightList li{

position:relative;
line-height:25px;
cursor:pointer;
padding-bottom:16px;
}
.rightList li span{

padding-left:5px;
border-bottom: 1px solid #e3e5eb;
}
.rightList li:before{

content: '';
position:absolute;
width:9px;
height:9px;
left:-24px;
border-radius:50%;
background: #FFFFFF;
border: 2px solid #EDEDED;
top:20%;
z-index:2;
}
/*.rightList li:after{
*/
/*content: '';*/
/*position:absolute;*/
/*width:9px;*/
/*height:9px;*/
/*border-radius:50%;*/
/*background:#fff;*/
/*left:-2px;*/
/*top:33%;*/
/*z-index:1;*/
/*}*/
.rightList li.active{

font-family: PingFangSC-Medium;
color: #20A0FF;
text-align: left;
line-height: 22px;
}
.rightList ul{

position:relative;
}
.rightList{

background:#fff;
right:10px;
box-shadow:0 0 5px 5px rgba(170,167,167,0.1);
z-index:13;
}
.rightList ul:after{

content:'';
width:1px;
height:100%;
display:inline-block;
background:#ccc;
position:absolute;
top:0;
left:20px;
}
.rightList .line_next{

display:inline-block;
width: 1px;
height:20px;
background:#ccc;
position:relative;
left:20px;
top:-15px;
}
.rightList .line_next:after{

content: '';
position:absolute;
width:9px;
height:9px;
border-radius:50%;
border:2px solid #EDEDED;
z-index:1;
left:-4px;
bottom: -8px;
}
.shownav.el-button.el-button--primary{

height:100px;
padding: 0 5px;
}
.shownav2.el-button.el-button--primary{

height:100px;
padding: 0 5px;
}
.slide-fade-enter-active{

transition: all 0.3s ease;
}
.slide-fade-leave-active{

transition: all 0.5s ease;
}
.slide-fade-enter, .slide-fade-leave-to{

/*transform: translateX(10px);*/
opacity:0;
}

Reference material :

版权声明
本文为[No Silver Bullet]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple