Home >
front end > JS/JQ how to determine the page scroll to the bottom, the navigation bar at the top of the float?
JS/JQ how to determine the page scroll to the bottom, the navigation bar at the top of the float?
<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "/& gt;
No title documents & lt;/title>
<style type="text/css">
The fixed - nav {
position: fixed;
width:100%;
Top: - 40 px;
- its - the transition: top. 5 s;
Moz - the transition: top. 5 s;
- o - the transition: top. 5 s;
The transition: top. 5 s;
- its - box - shadow: 0 px 2 px rgba (, 0, 0, 1);
- moz - box - shadow: 0 px 2 px rgba (, 0, 0, 1);
Box - shadow: 0 px 2 px rgba (, 0, 0, 1);
}
The fixed - nav - appear {top: 0; }
</style>
<body>
11111111 & lt; br/> 222222
Var $navxf=$(' # Jnav), navTop=$navxf. Offset (). The top, navH=$navxf. OuterHeight (), winTop_1=0, winWidth=$(window), width (), holder=jQuery (' & lt; div> ');
$(window) on (' scroll ', function () {
Var winTop_2=$(window). ScrollTop ();
Holder. The CSS (' height 'navH);
//float, but does not display,
If (winTop_2 & gt; NavTop & amp; & WinWidth> 980) {
Holder. The show (). The insertBefore ($navxf);
$navxf. AddClass (' fixed - nav);
} else {
Holder. Hide ();
$navxf. RemoveClass (' fixed - nav);
}
//judge the mouse scroll up, show,
If (winTop_2 & gt; WinTop_1 & amp; & WinWidth> 980) {
$navxf. RemoveClass (' fixed - nav - appear ');
} else if (winTop_2 & lt; WinTop_1) {
$navxf. AddClass (' fixed - nav - appear ');
}
WinTop_1=$(window). ScrollTop ();
})
</script>