This repository has been archived on 2023-02-03. You can view files and clone it, but cannot push or open issues or pull requests.
autonomic.zone/js/fixHeader.js

58 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-08-31 11:44:57 +00:00
var cj = cj ? cj : {};
(function($) {
$.extend(cj, {
fixHeader: {
// jQuery DOM caching
$nav: null,
$header: null,
// CSS selectors
navSelector: '.navigation',
headerSelector: '.header',
// Classes
fixedClass: 'navigation--fixed',
// Misc
navHeight: 0,
headerHeight: 0,
init: function() {
var self = this;
self.$nav = $(self.navSelector);
self.$header = $(self.headerSelector);
if (!self.$nav || !self.$nav.length) {
return;
}
if (!self.$header || !self.$header.length) {
return;
}
self.navHeight = self.$nav.outerHeight();
self.headerHeight = self.$header.outerHeight() - self.navHeight;
self.$navigationClone = self.$nav.clone();
self.$navigationClone.addClass('navigation--clone');
self.$navigationClone.appendTo(self.$header);
self.$navigationClone.hide();
self.bindEvents();
},
bindEvents: function() {
var self = this;
$(window).scroll(function () {
if ($(this).scrollTop() > self.headerHeight) {
self.$nav.addClass(self.fixedClass);
self.$navigationClone.show();
} else {
self.$nav.removeClass(self.fixedClass);
self.$navigationClone.hide();
}
});
}
}
});
$.subscribe('pageReady', function() {
cj.fixHeader.init();
});
}(jQuery));