当前位置:网站首页>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 :
边栏推荐
- Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
- SQL Injection (GET/Search)
- Richview trvstyle liststyle list style (bullet number)
- JS continues to explore...
- Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
- Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
- selenium 浏览器(1)
- The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
- 记录关于银行回调post请求405 问题
- 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
猜你喜欢
FPGA测试方法以Mentor工具为例
[email protected] Nanoparticles) | nano metal organic framework carry"/>
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
QT learning 20 standard dialog box in QT (middle)
PhpMyAdmin stage file contains analysis traceability
Example analysis of QT learning 18 login dialog box
[technology development-24]: characteristics of existing IOT communication technology
Programmable logic device software testing
Flutter dynamic | fair 2.5.0 new version features
随机推荐
Leetcode-1175.Prime Arrangements
树的深入和广度优先遍历(不考虑二叉树)
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
selenium 浏览器(1)
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
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
Richview trvstyle liststyle list style (bullet number)
[556. Next larger element III]
GoLand 2021.2 configure go (go1.17.6)
Conversion function and explicit
Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(
Uniapp skills - scrolling components -1
Leetcode-1175. Prime Arrangements
windos 创建cordova 提示 因为在此系统上禁止运行脚本
Mastering the cypress command line options is the basis for truly mastering cypress
Global event bus
Spring cup eight school league
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
GoLand 2021.1: rename the go project