2
假設我有標題詞就像下面多個固定標題
<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.How我可以做到這一點?
下面我已經試過..
$(window).scroll(function() {
if ($(this).scrollTop()) { //Here some condition which finds if the heading tag is in screenview.
$('.fixontop').css({
'display': 'fixed'
});
}
});
這裏是小提琴http://jsfiddle.net/0can8pt9/
嘗試使用'.each()'來定位每個元素的'.fixontop'類。 –
[Freeze Header until Irrelevant(HTML,CSS and JS)]可能的重複](http://stackoverflow.com/questions/7385068/freeze-header-until-irrelevant-html-css-and-js) – jcuenod