0
我试图让一个子菜单停留在页面的顶部,同时滚动一次它在滚动期间到达顶部。以下是我迄今为止:菜单栏固定在页面顶部,当滚动导致下面的内容在滚动期间跳跃
$(window).scroll(function() {
if ($(window).scrollTop() > 175) {
$('#location_menu').css('position', 'fixed').css('top','0px').css('z-index','1000');
$('.first').css('padding-top','415');}
else {
$('#location_menu').css('position', 'relative').css('z-index','1');
}});
我遇到的问题是,滚动不顺畅,一旦从位置上的元素变化:相对于位置:固定的内容似乎跳/约跳过了415px与子菜单高度相同。
这里是CSS:
<div id="location_menu" >submenu content
</div>
<div id="content" class="location_detail first">content beneath submenu
</div>
我已经添加了.first
行至有415px填充顶页面时crolling和内页.css('padding-top','415')
这并未顶部的175px达到实际上似乎没有做任何事情。没有改变,所以我认为我错误地执行了它。
我应该使用不同的滚动功能,然后我已经在上面列出?
这里是我结束了使用,以解决我的问题,从@Danko基于断码:
$(window).scroll(function() {
var $conten = $('.first'),
$menu = $('#location_menu')
scrollpos = $(window).scrollTop();
if (scrollpos >= 175) {
$conten.css('padding-top','365px');
$menu.css('position', 'fixed').css('top','0px').css('z-index','1000');
} else {
$conten.css('padding-top','0');
$menu.css('position', 'fixed').css('position', 'relative').css('z-index','1');
}
});