【发布时间】:2017-02-26 09:04:26
【问题描述】:
我只想在主要内容的顶部显示粘性页眉 - 即,一旦页脚 div 的顶部到达窗口顶部,粘性部分就会隐藏。
<body>
<p> </p>
<p> </p>
<p>CONTENT BEFORE STICKY SECTION</p>
<p> </p>
<p> </p>
<!-- our markup -->
<header>
<h1>Sticky Section</h1></header>
<div class="content" style="background-color:#7BD2D5; height:1000px; padding:200px 20px;"> <!-- this is the area id like to display the sticky section at the top of the page only-->
MAIN CONTENT - SHOW STICKY BAR WHEN THIS SECTION IS IN VIEW
</div>
<div class="fonnter" style="line-height:1000px; padding-top:400px;"><!-- Remove sticky section once scrolled to footer content-->
<p>FOOTER CONTENT - Hide sticky section at the top of the page</p>
</div>
<script>
$(window).scroll(function() {
if ($(this).scrollTop() > 100){
$('header').addClass("sticky");
}
else{
$('header').removeClass("sticky");
}
});
</script>
如何更改 > 100 的值以改为查找 div 容器?
【问题讨论】: