This article example shares the specific code of Vue + element UI to achieve anchor positioning for your reference. The specific content is as follows vue <el-row :gutter="20"> <el-col :span="3"> <!--Navigation selection event--> <el-menu :default-active="activeStep" @select="jump"> <el-menu-item v-for="(item,index) in menuData" :index="`${index}`" :key="item.subjectId"> <i class="el-icon-menu"></i> <span slot="title">{{item.subjectName}}</span> </el-menu-item> </el-menu> </el-col> <!--Binding scroll events requires listening--> <el-col :span="21" class="scroll_cls" @scroll="onScroll"> <div v-for="(item,index) in tableObject" :key="index" style="height:500px"> <div class="title scroll-item" :id="item.name">{{item.name}}</div> <el-table :data="item.rows" :key="index"> <el-table-column label="Serial number" type="index" width="50"></el-table-column> <el-table-column prop="channelId" label="Channel/Team ID"></el-table-column> <el-table-column prop="channelName" label="Channel/Team"></el-table-column> <el-table-column prop="ruleCode" label="allocation plan id"></el-table-column> <el-table-column prop="ruleName" label="Allocation plan name"></el-table-column> <el-table-column prop="ruleVersion" label="version number"></el-table-column> <el-table-column prop="hierarchy" label="Level"> <template slot-scope="scope"> <span>{{scope.row.hierarchy == 1 ? 'Project' : 'Channel Team'}}</span> </template> </el-table-column> <el-table-column label="Validity period"> <template slot-scope="scope"> <span>{{scope.row.beginTime + '-' + scope.row.endTime}}</span> </template> </el-table-column> <el-table-column prop="creatorName" label="Operator"></el-table-column> <el-table-column prop="createTime" label="Operation time"></el-table-column> <el-table-column prop="orderCnt" label="Related Order"> <template slot-scope="scope"> <el-button @click="orderHandleClick(scope.row.orderCnt)" type="text" size="small" >{{scope.row.orderCnt}}</el-button> </template> </el-table-column> <el-table-column label="operation"> <template slot-scope="scope"> <el-button @click="settingHandleClick(scope.row)" type="text" size="small">Set allocation plan</el-button> </template> </el-table-column> </el-table> <el-pagination v-if="item.total > 5" style="margin-top: 15px" size="small" @size-change="handleSizeChange($event,index)" @current-change="handleCurrentChange($event,index)" :current-page="ruleForm.ageNum" :page-sizes="[10, 30, 50, 100]" :page-size="ruleForm.pageSize" layout="total, sizes, prev, pager, next" :total="item.total" ></el-pagination> </div> </el-col> </el-row> js //Scroll trigger button highlight methods: { onScroll(e) { let scrollItems = document.querySelectorAll(".scroll-item"); console.log(scrollItems) console.log(e) for (let i = scrollItems.length - 1; i >= 0; i--) { //Judge whether the scroll bar scroll distance is greater than the scrollable distance of the current scroll item let judge = e.target.scrollTop >= scrollItems[i].offsetTop - scrollItems[0].offsetTop; if (judge) { console.log(i) this.activeStep = i.toString(); break; } } }, jump(index) { console.log(index) let target = document.querySelector(".scroll_cls"); let scrollItems = document.querySelectorAll(".scroll-item"); // Determine whether the scroll bar has scrolled to the bottom if (target.scrollHeight <= target.scrollTop + target.clientHeight) { console.log(index) console.log(typeof index) this.activeStep = index; } let total = scrollItems[index].offsetTop - scrollItems[0].offsetTop; // The distance between the anchor element and the top of its offsetParent (here is body) (the distance to be scrolled) console.log(total) let distance = document.querySelector(".scroll_cls").scrollTop; // The distance between the scroll bar and the top of the scroll area console.log(distance) // let distance = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset // The distance between the scroll bar and the top of the scroll area (the scroll area is the window) // Scrolling animation implementation, use setTimeout recursion to achieve smooth scrolling, divide the distance into 50 small segments, and scroll once every 10ms // Calculate the distance of each small segment let step = total / 50; if (total > distance) { smoothDown(document.querySelector(".scroll_cls")); } else { let newTotal = distance - total; step = newTotal / 50; smoothUp(document.querySelector(".scroll_cls")); } // Parameter element is the scrolling area function smoothDown(element) { if (distance < total) { distance += step; element.scrollTop = distance; setTimeout(smoothDown.bind(this, element), 10); } else { element.scrollTop = total; } } // Parameter element is the scrolling area function smoothUp(element) { if (distance > total) { distance -= step; element.scrollTop = distance; setTimeout(smoothUp.bind(this, element), 10); } else { element.scrollTop = total; } } document.querySelectorAll('.scroll-item').forEach((item, index1) => { if (index === index1) { item.scrollIntoView({ block: 'start', behavior: 'smooth' }) } }) }, }, mounted() { this.$nextTick(() => { console.log(1) window.addEventListener('scroll', this.onScroll,true) }) }, CSS .scroll_cls { height: 500px; overflow:auto; } Reprinted from: Click here for the original link The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: linux exa command (better file display experience than ls)
>>: A brief talk about Mysql index and redis jump table
Table of contents 1. Installation 2. Introducing ...
This article shares with you how to use the Vue c...
This article is compiled with reference to the My...
Table of contents Preface Asynchronous loading Pa...
A simple license plate input component (vue) for ...
bmi Voyager Pitchfork Ulster Grocer Chow True/Sla...
MySQL5.7 master-slave configuration implementatio...
rm Command The rm command is a command that most ...
#String concatenation concat(s1,s2); concatenate ...
1. Space rules Whitespace within HTML code is usu...
Using mask layers in web pages can prevent repeat...
Let’s build the data table first. use test; creat...
Version Chain In InnoDB engine tables, there are ...
There is often a lack of understanding of multi-c...
Forgetting the password is a headache. What shoul...