Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created August 7, 2020 20:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/6d4599f79725a292ca56f869bd2e6ab3 to your computer and use it in GitHub Desktop.
Save Garconis/6d4599f79725a292ca56f869bd2e6ab3 to your computer and use it in GitHub Desktop.
Divi | Adjust anchor Smooth Scroll top position based on Theme Builder fixed header height
jQuery(function($) {
window.et_pb_smooth_scroll = function($target, $top_section, speed, easing) {
var $window_width = $(window).width();
$menu_offset = -1;
var headerHeight = 143;
if ($('#wpadminbar').length && $window_width <= 980) {
$menu_offset += $('#wpadminbar').outerHeight() + headerHeight;
}
else {
$menu_offset += headerHeight;
}
//fix sidenav scroll to top
if ($top_section) {
$scroll_position = 0;
}
else {
$scroll_position = $target.offset().top - $menu_offset;
}
// set swing (animate's scrollTop default) as default value
if (typeof easing === 'undefined') {
easing = 'swing';
}
$('html, body').animate({ scrollTop: $scroll_position }, speed, easing);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment