我认为,要做到这一点最简单的方法是使用jQuery的一点点。 添加此功能:
它将创建一个新的类,您可以使用菜单样式。
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 900) { //Choose where on the page to add new class, here i'ts 900px from the page top
$("nav").addClass("scrolling");
} else {
$("nav").removeClass("scrolling");
}
});
CSS例子:
nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
min-height: 50px;
padding: 10px;
background-color: transparent;
width: 100%;
}
nav.scrolling {
background-color: #000;
}
看看这里: http://codepen.io/Winterfox/pen/QNrqRb
这样你就不必创建两个几乎exacty寻找menues。