How to add offset to anchor scroll to behavior?
General Discussion
4
Posts
2
Posters
210
Views
-
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
Online Users
Forgot your key, lost your files, need a previous Lay Theme or Addon version?
Go to www.laykeymanager.com