当前位置:网站首页>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 :
边栏推荐
- Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
- Dynamic programming 01 knapsack and complete knapsack
- GoLand 2021.2 configure go (go1.17.6)
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- Spring cup eight school league
- [556. Next larger element III]
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- PHP maze game
- How to delete an attribute or method of an object
- Function calling convention
猜你喜欢

Go language web development series 27: Gin framework: using gin swagger to implement interface documents

MySQL 数据处理值增删改

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

RocksDB LRUCache

Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;

如何使用lxml判断网站公告是否更新

Implementation of Muduo accept connection, disconnection and sending data
![[technology development-24]: characteristics of existing IOT communication technology](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[technology development-24]: characteristics of existing IOT communication technology

Uniapp tips - scrolling components
随机推荐
PHP maze game
【556. 下一个更大元素 III】
[technology development-24]: characteristics of existing IOT communication technology
Qt学习19 Qt 中的标准对话框(上)
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
MySQL 数据增删改查综合案例
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
Uniapp tips - scrolling components
QT learning 17 dialog box and its types
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
Go language unit test 3: go language uses gocovey library to do unit test
QT learning 20 standard dialog box in QT (middle)
How to promote the progress of project collaboration | community essay solicitation
Dlopen() implements dynamic loading of third-party libraries
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
Comprehensive case of MySQL data addition, deletion, modification and query
[技术发展-24]:现有物联网通信技术特点
[技術發展-24]:現有物聯網通信技術特點
QT learning 22 layout manager (I)