Estou tentando fazer este código para trocar o elemento quando o mesmo atingir o topo, o elemento ficara fixo ate que o próximo atinja o top.
HTML
<p>
elemento A
</p>
<p>
elemento B
</p>
<p>
elemento C
</p>
JS
function scroll() {
(window).scroll(function() {
if ($(window).scrollTop() > elementPosition.top) {
$('p').css('position', 'fixed').css('top', '0');
} else {
$('p').css('position', 'static');
}
});
}