Suppose I have headings like below
<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.
So When I scroll Heading 1 should be fixed on top and I scroll down heading 2 should be fixed and all other headings fixed position must be removed.I think it is only possible via jquery.How can i do it ?
I have tried below..
$(window).scroll(function() {
if ($(this).scrollTop() ) { //Here some condition which finds if the heading tag is in screenview.
$('.fixontop').css({
'display': 'fixed'
});
}
});
Here is fiddle http://jsfiddle.net/0can8pt9/