当前位置:网站首页>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装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
- PHP maze game
- [how to earn a million passive income]
- 挡不住了,国产芯片再度突进,部分环节已进到4nm
- Using registered classes to realize specific type matching function template
- Collection of mobile adaptation related articles
- 金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
- [understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
- FPGA测试方法以Mentor工具为例
- 核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
猜你喜欢

挡不住了,国产芯片再度突进,部分环节已进到4nm
![[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered

PhpMyAdmin stage file contains analysis traceability

Flutter dynamic | fair 2.5.0 new version features

Rasp implementation of PHP
![[technology development-24]: characteristics of existing IOT communication technology](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[technology development-24]: characteristics of existing IOT communication technology

Installation impression notes
[email"/>Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email

SQL Injection (POST/Select)

Qt学习25 布局管理器(四)
随机推荐
挡不住了,国产芯片再度突进,部分环节已进到4nm
Ocean CMS vulnerability - search php
JVM系列——概述,程序计数器day1-1
全局事件总线
Golang - command line tool Cobra
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
[ACNOI2022]猜数
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe for the online account manager to open an account
Qt学习24 布局管理器(三)
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
Conversion function and explicit
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
[556. Next larger element III]
C language standard IO function sorting
[acnoi2022] guess numbers
Richview trvstyle liststyle list style (bullet number)
Uniapp tips - scrolling components
Comprehensive case of MySQL data addition, deletion, modification and query