- This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
Viewing 9 posts - 1 through 9 (of 9 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Animate Scroll Links
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.
‘
‘
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…
Best suggestion I had without seeing an actual demo.
I’ve put it on codepen
Ah simple mistake! i was putting it inside the containing element. Thanks.
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.
Have a look at the earlier link, adding a fade is a small adjustment. Gets a bit more complicated beyond that.