Code snippet: http://jsfiddle.net/R3G2K/1/
In my project, there are multiple divs with content and each div has a header. My goal is to make the last header that goes out of viewport "sticky" or fixed at the top.
I have explored various solutions for this issue, but none of them seem to be effective when dealing with multiple headers.
$('.content').scroll(function(){
console.log('scrolling')
$('.itemheader').each(function(){
var top = $(this).offset().top;
console.log(top);
if(top<25){
$(this).addClass('stick');
} else {
$(this).removeClass('stick');
}
})
});
I suspect the problem lies in the fact that each header shares the same class name without a unique identifier, causing my previous attempt to fail.