This thing actually understood very understood, is the application of position:fixed
Examples are as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<style type= "Text/css" >
. Wrapper{width:1000px;height:2000px;margin-left:auto;margin-right:auto;}
. header{height:150px;}
#nav {padding:10px;position:relative;top:0;background:black;width:1000px;}
a{display:inline-block;margin:0 10px;*display:inline;zoom:1;color:white;}
</style>
<body>
<div class= "wrapper" >
<div class= "Header" ></div>
<div id= "NAV" >
<a href= "#" >11111</a>
<a href= "#" >22222</a>
<a href= "#" >33333</a>
<a href= "#" >44444</a>
<a href= "#" >55555</a>
</div>
</div>
</body>
<script type= "Text/javascript" src= "Menufixed.js" ></script>
<script type= "Text/javascript" >
Window.onload = function () {
Menufixed (' Nav ');
}
</script>
/*js*/
JavaScript Document
function menufixed (ID) {
var obj = document.getElementById (ID);
var _getheight = obj.offsettop;
Window.onscroll = function () {
Changepos (Id,_getheight);
}
}
function Changepos (id,height) {
var obj = document.getElementById (ID);
var scrolltop = Document.documentElement.scrollTop | | Document.body.scrollTop;
if (ScrollTop < height) {
obj.style.position = ' relative ';
}else{
obj.style.position = ' fixed ';
}
}
Floating navigation is actually divided into several styles, either above, below, in the side of those ads I don't say--!
The only thing to consider is when your navigation is not at the top, how much to scroll the window to navigate (scrolltop This is the window scrolling value),
To add a title bar, you need to consider the window scrolling distance and the height (height) of the ad column; scrolltop < height This is the window scrolling distance is not higher than the title bar,
I don't need to say you know it, when scrolltop > height give a fixed positioning on it, is usually fixed in top:0 that, how the capital to see your needs.
What's wrong please point out, thank you, sharing is a virtue!
In fact, I do is mobile, do not know is not the speed of the problem or how, I slide when the navigation switch is very slow, that effect is not good to see, I looked for a long time did not find any reason, there is the great God know to share experience, thank you!
Some projects need something to integrate (2)--floating navigation