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
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it
Forgot your key, lost your files, need a previous Lay Theme or Addon version?
Go to www.laykeymanager.com