Дополнен 4 года назад
(function(){
var nav = document.getElementById("nav");
nav.style.cssText = "float: left; position: relative; width: 100%; height: 200px; background: red;";
})();
onscroll = function(){
var y = pageYOffset,
yTop = 200,
result = yTop - y;
if(result >= 100){
nav.style.cssText = "float: left; position: relative; width: 100%; height: 200px; background: green;";
if(result <= 100){
nav.style.cssText += "top: 0px; position: fixed; float: left;";
}
}
if(result >= 100){
nav.style.height = result + "px";
}
}
Дополнен 4 года назад
body{
margin: 0px;
padding: 0px;
}
#wrap{
width: 100%;
height: 1000px;
}
#menuMain{
float: left;
position: relative;
width: 100%;
height: 100px;
background: gold;
}
Дополнен 4 года назад
div id="wrap">
nav id="menuMain">/nav>
nav id="nav">/nav>
/div>