当前位置:网站首页>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 :
边栏推荐
- 从零开始的基于百度大脑EasyData的多人协同数据标注
- QT learning 21 standard dialog box in QT (Part 2)
- 交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
- JVM class loading
- Golang — template
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- Message subscription and publishing
- Conversion function and explicit
- Qt学习18 登录对话框实例分析
猜你喜欢

MySQL 数据增删改查综合案例

JVM runtime data area

Programmable logic device software testing

Dlopen() implements dynamic loading of third-party libraries

Qt学习19 Qt 中的标准对话框(上)

QT learning 21 standard dialog box in QT (Part 2)
[email protected])|制备路线"/>叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线

Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases

MySQL 数据处理值增删改
![[技术发展-24]:现有物联网通信技术特点](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[技术发展-24]:现有物联网通信技术特点
随机推荐
windos 创建cordova 提示 因为在此系统上禁止运行脚本
Windos creates Cordova prompt because running scripts is prohibited on this system
JS download files through URL links
jvm-对象生命周期
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Screenshot of the operation steps of upload labs level 4-level 9
Qt学习24 布局管理器(三)
QT learning 24 layout manager (III)
MySQL 数据处理值增删改
GoLand 2021.1.1: configure the multi line display of the tab of the open file
[combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
[technology development-24]: characteristics of existing IOT communication technology
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Logback log sorting
RocksDB LRUCache
JVM object lifecycle
Go 1.16.4: purpose of go mod tidy