【发布时间】:2015-06-20 19:29:48
【问题描述】:
假设我有如下标题
<h1 class="fixontop">heading 1</h1>
content goes here.
.
.
.
long paragraph.
<h1 class="fixontop">heading 2</h1>
2nd content goes here.
.
.
.
long paragraph.
<h1 class="fixontop">heading 3</h1>
3nd content goes here.
.
.
.
long paragraph.
所以当我滚动时,标题 1 应该固定在顶部,我向下滚动时,标题 2 应该固定,所有其他标题固定位置必须删除。我认为只能通过 jquery 实现。我该怎么做?
我在下面尝试过..
$(window).scroll(function() {
if ($(this).scrollTop() ) { //Here some condition which finds if the heading tag is in screenview.
$('.fixontop').css({
'display': 'fixed'
});
}
});
【问题讨论】:
-
尝试使用
.each()定位每个元素的.fixontop类。
标签: javascript jquery css