Q:

How prevent scroll to top after scroll to element

maybe it's newbie question but I'm really confused. I have code which supposed to navigate me on page. I have got "abc" navigation section, when I'm clicking on any letter, page scrolling to letter's section. When I'm clicking on another letter, page scrolling to top. Why it happening?
$('#abc li').on('click',function (e) {
    e.preventDefault();
    var target = $("#"+$(this).text());
if(target.offset()){
    var offs = target.offset().top;
    console.log(target, offs);
    if ($(this).hasClass('pressed')) {
        return false;
    } else {
        $('.pressed').removeClass('pressed');
        $('#needToScroll').animate({scrollTop: offs - 115}, 400);
    }
    $(this).addClass('pressed');
}
else{
    console.log('undef sel');
} });

I've got fiddle of this here. Pls someone explain me.

A:

offset() returns a relative offset. You'll need to factor in the amount you've already scrolled. See here: jquery offset values changes by scrolling the page

