Skip to content

Instantly share code, notes, and snippets.

@DarrylD DarrylD/stickyheader.js
Last active Dec 27, 2015

Embed
What would you like to do?
Simple fixed header after trigger point
(function(){
var triggerElement = $(".container") //element to he used to trigger the fixed header
, header = $(".header") //element of header
, stickyClass = "stickit" // class to be used to give the fixed header a fixed position
$(window).scroll(function(){
var offset = 0,sticky = false,top = $(window).scrollTop();
if (triggerElement.offset().top < top) {
header.addClass(stickyClass)
sticky = true;
} else {
header.removeClass(stickyClass).removeAttr('style');
}
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.