我的博客有一个固定的顶部标题栏。当用户向下滚动某个特定点时,我希望在第一个标题的顶部显示另一个标题栏。
我用jQuery航路点来实现它。很好用。
我已经添加了转换,所以当它出现时,它会向下滑动。它也很好用。
但问题是当我向上滚动时,转换不会发生。
这是我的代码:
<div id="share-bar" class="sticky-wrapper">This is second header</div>
<div id="header">This is normal header</div>
<p id="trigger">THIS IS THE PLACE WHERE SECOND BAR COMES UP</p>
JS公司
$('#trigger').waypoint(function(){
$( "#share-bar" ).toggleClass("stuck");
});
CSS
#header {
height: 55px;
background-color: black;
color: white;
position: fixed;
top: 0;
width: 100%;
}
#share-bar {
background: none repeat scroll 0 0 #FFFFFF;
border-bottom: 1px solid #DDDDDD;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.15);
float: left;
height: 55px;
padding: 0;
width: 100%;
transition: all 0.2s ease 0s;
}
.sticky-wrapper { position:absolute; top:-55px; }
.stuck {
position: fixed;
top: 0;
width: 100%;
z-index: 999;
transition: all 0.2s ease 0s;
}
我有一个working Fiddle here
我的问题是:
为什么从-55px绝对值转换到0固定值而不是相反?
我做错什么了?请引导我。我卡住了。
最佳答案
移动
'position: fixed;'
'z-index: 999;'
#share-bar
和off.stuck
修复了这个问题。尝试this fiddle