我在屏幕中间有一个菜单。它包含一些下拉菜单列表,当用户滚动到某个点时,它会停留在页面顶部。
<div class="discover_filter ">
<div class="filter1">
<p class="menuitem">Type</p>
<ul>
<li>Option</li>
</ul>
</div>
<div class="filter1">
<p class="menuitem">Location</p>
<ul>
<li>Option</li>
</ul>
</div>
<div class="filter1">
<p class="menuitem">Industry</p>
<ul>
<li>Option</li>
</ul>
</div>
<div class="filter1">
<p class="menuitem">Featured</p>
<ul>
<li>Option</li>
</ul>
</div>
</div>
CSS:
.discover_filter {
width: 980px%;
height: 50px;
background-color: #ea8f18;
padding: 0 40px;
}
.stick {
position: fixed;
top: 103px;
z-index: 9999;
width:980px;
}
.filter1 {
float: left;
z-index:9999;
cursor: pointer;
height:50px;
background-color:#ea8f18;
width: 170px;
color: white;
overflow: hidden;
.menuitem {
font-weight: bold;
display:block;
height:20px; width: 150px;
padding: 15px 10px;
font-size: 15pt;
}
和 Javascript:
$('.filter1').hover(function() {
$(this).animate({ 'height': '400px' }, 250);
}, function() {
$(this).animate({ 'height': '50px' }, 250);
});
var s = $(".discover_filter");
var pos = s.position();
$(window).scroll(function() {
var windowpos = $(window).scrollTop();
if (windowpos >= 400) {
s.addClass("stick");
} else {
s.removeClass("stick");
}
});
问题是,菜单将其下方的页面向下推,除非菜单已正确固定到页面顶部(一旦用户滚动足够远)。
如何在不向下推页面的情况下使菜单正确覆盖?