How to add offset to anchor scroll to behavior?
-
Hi all,
the following code is already part of lay theme right?
https://gist.github.com/aunruh/7d06859bedcf0ce780e05e73659f8c48However the anchor scroll to behavior works fine.
Because of a fixed navbar I need to add an offset to it.
How does it works?Best Manuel
-
Dear @justfunk
look here:
I added: var top = el.offset().top+100;<script> jQuery(document).on( 'click', 'a[href^="#"]', function(e){ e.preventDefault(); var hash = jQuery(this).attr('href'); var el = jQuery(hash); var top = el.offset().top+100; jQuery('html, body').animate({ scrollTop: top }, 300, 'swing', function() { window.location.hash = hash; } ); } ); window.laytheme.on('newpageshown', function(){ var hash = window.location.hash; var el = jQuery(hash); if(el.length > 0) { var top = el.offset().top; window.scroll(0, top); } }); </script>Best!
Marius
-
-
Dear @justfunk
the code should be added in the CUSTOM CODE section.
Then it will be fine.
Best!
Marius
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login