Yoshi Peters
Yoshi Peters

Reputation: 196

Jquery scrolltop won't work with offset

Hi I got a small problem with jQuery, when the function runs for the first time it doesn't seem to notice the -60 px for my sticky header. After that, it works great, I have no clue what's wrong.

You can test it out for yourself here http://test.peekmanagement.com/

    $("#link_to_services").click(function() {
        $('html, body').animate({
            scrollTop: $("#services").offset().top - 60
        }, 2000);
    });

Upvotes: 0

Views: 196

Answers (2)

Giacomo Paita
Giacomo Paita

Reputation: 1419

As I suggest in the comment, try something like this (not real js, but in 'metalanguage', just to explain):

     $('<div class="replaced-container" />')
        .height($actualHeader.height())
        .width($actualHeader.width())
        .appendTo($actualHeaderContainer);

And, on page scroll:

    if (pageScrollTop is > of the firstScene) {
       $('.replaced-container').show();
    } else {
     $('.replaced-container').hide();
    }

Upvotes: 1

Giacomo Paita
Giacomo Paita

Reputation: 1419

Try to call the function on $(window).load, not at document ready.

Upvotes: 0

Related Questions