Created
September 20, 2018 14:55
-
-
Save mindpalette/a5835d91281fa77a6148f6cc75e9ea4c to your computer and use it in GitHub Desktop.
Scroll to Element with Fixed Header Offset (WordPress, Elementor)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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