Skip to content

Instantly share code, notes, and snippets.

@mindpalette
Created September 20, 2018 14:55
Show Gist options
  • Save mindpalette/a5835d91281fa77a6148f6cc75e9ea4c to your computer and use it in GitHub Desktop.
Save mindpalette/a5835d91281fa77a6148f6cc75e9ea4c to your computer and use it in GitHub Desktop.
Scroll to Element with Fixed Header Offset (WordPress, Elementor)
jQuery(document).ready(function($) {
// specify the header element (used for offset height and fixed positioning check)
var fixedheader = $("#top-banner-navbar");
// trigger for links with class scroll-offset-header
$(document).on("click", ".scroll-offset-header", function(e) {
if ($(fixedheader).css("position") === "fixed") {
e.preventDefault();
e.stopImmediatePropagation();
$('html, body').stop();
var target = $(this).attr("href");
var offset = $(fixedheader).height();
$('html, body').animate({scrollTop: $(target).offset().top - offset }, 400);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment