58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
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)); |