Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Animate Scroll Links

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #250878
    GZA
    Participant

    How can update this script so that it animates to the top of the page when i click .logo #top link in my header? Currently it’s only animating links that are below the header.

    http://dpaste.com/0P4M36P

    #250881
    Shikkediel
    Participant

    This should work, as far as I can tell:

    if (target.length) {
    
      if (target[0] == '#top') var gap = 0;
      else gap = 100;
    
      $('html, body').animate({
        scrollTop: target.offset().top-gap
      }, 1000);
    }
    

    Needed an edit, I believe…

    #250885
    GZA
    Participant

    That didnt work. When i click the logo it still goes straight to the top of the page without animating

    #250887
    Shikkediel
    Participant

    Best suggestion I had without seeing an actual demo.

    #250905
    GZA
    Participant

    I’ve put it on codepen

    http://codepen.io/gza/pen/ygjpBy

    #250907
    Shikkediel
    Participant

    There was no element with id="top" to scroll to…

    <header id="top">
    

    codepen.io/anon/pen/jyxZbB

    #250925
    GZA
    Participant

    Ah simple mistake! i was putting it inside the containing element. Thanks.

    #250926
    GZA
    Participant

    Is there a way to add a smooth transition to the navbar also?

    for example – if you scroll down to the bottom 150px you’ll see it just snaps down just after it affixes to the top.

    #250940
    Shikkediel
    Participant

    Have a look at the earlier link, adding a fade is a small adjustment. Gets a bit more complicated beyond that.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.