当前位置:网站首页>Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
2022-07-03 14:03:00 【starcpdk】
We often see the content of some websites decline , The navigation bar is fixed at the top , How is such a function realized ?
I am here vue The implementation of the
stay vue Paste the following code into the hook function of ,
Then we add one on the tab of our navigation bar id = "inner" Properties of
mounted() {
// The navigation bar scrolls with the page to detect
// In the page nav Tag plus id="inner" This is an attribute
let obj11 = document.getElementById("inner");
let top11 = getTop(obj11);
let isIE6 = /msie 6/i.test(navigator.userAgent);
window.onscroll = function () {
let bodyScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if (bodyScrollTop > top11) {
obj11.style.position = (isIE6) ? "absolute" : "fixed";
obj11.style.top = (isIE6) ? bodyScrollTop + "px" : "0px";
obj11.style.zIndex = (isIE6) ? "-1" : "1";
} else {
obj11.style.position = "static";
}
}
function getTop(e) {
let offset = e.offsetTop;
if (e.offsetParent != null) offset += getTop(e.offsetParent);
return offset;
}
}
The effect is as follows :
边栏推荐
- Global event bus
- Leetcode-1175. Prime Arrangements
- JS download files through URL links
- Golang — template
- JVM runtime data area
- Qt学习19 Qt 中的标准对话框(上)
- GoLand 2021.1.1: configure the multi line display of the tab of the open file
- 信创产业现状、分析与预测
- Sequence table (implemented in C language)
- Screenshot of the operation steps of upload labs level 4-level 9
猜你喜欢
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
QT learning 20 standard dialog box in QT (middle)
jvm-对象生命周期
GoLand 2021.1.1: configure the multi line display of the tab of the open file
QT learning 22 layout manager (I)
【吉林大学】考研初试复试资料分享
Qt学习25 布局管理器(四)
Current situation, analysis and prediction of information and innovation industry
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Qt学习17 对话框及其类型
随机推荐
项目协作的进度如何推进| 社区征文
How to use lxml to judge whether the website announcement is updated
jvm-类加载
JS general form submission 1-onsubmit
Failure of vector insertion element iterator in STL
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
Selenium browser (1)
C language standard IO function sorting
FPGA test method takes mentor tool as an example
Comprehensive case of MySQL data addition, deletion, modification and query
JVM系列——概述,程序计数器day1-1
Qt学习21 Qt 中的标准对话框(下)
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
MySQL data processing value addition, deletion and modification
The solution of Chinese font garbled code in keil5
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
记录关于银行回调post请求405 问题
JS download files through URL links
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)