当前位置:网站首页>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
- 金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
- Summary of common error reporting problems and positioning methods of thrift
- 树的深入和广度优先遍历(不考虑二叉树)
- Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
- [技术发展-24]:现有物联网通信技术特点
- Function calling convention
- Qt学习19 Qt 中的标准对话框(上)
- Selenium browser (1)
- Golang — template
猜你喜欢

Go: send the get request and parse the return JSON (go1.16.4)
![[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes

FPGA测试方法以Mentor工具为例

JVM class loading

使用vscode查看Hex或UTF-8编码

GoLand 2021.1.1: configure the multi line display of the tab of the open file

Golang - command line tool Cobra

QT learning 25 layout manager (4)
[email protected])|制备路线"/>叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线

Qt学习17 对话框及其类型
随机推荐
Qt学习25 布局管理器(四)
JS new challenges
There is nothing new under the sun. Can the meta universe go higher?
QT learning 22 layout manager (I)
Software testing is so hard to find, only outsourcing offers, should I go?
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
如何使用lxml判断网站公告是否更新
Qt学习18 登录对话框实例分析
项目协作的进度如何推进| 社区征文
叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
使用vscode查看Hex或UTF-8编码
jvm-运行时数据区
QT learning 25 layout manager (4)
Field problems in MySQL
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
Ocean CMS vulnerability - search php
How to delete an attribute or method of an object
[acnoi2022] guess numbers
Go language web development series 30: gin: grouping by version for routing
[556. Next larger element III]