47 lines
917 B
JavaScript
47 lines
917 B
JavaScript
/*
|
|
* Custom code goes here.
|
|
* A template should always ship with an empty custom.js
|
|
*/
|
|
jQuery(window).on('load', function () {
|
|
var $ = jQuery;
|
|
|
|
var $box = $('.nav_menu_box');
|
|
if (!$box.length) return;
|
|
|
|
var boxTop = 0;
|
|
var boxHeight = 0;
|
|
|
|
function recalc() {
|
|
boxTop = $box.offset().top;
|
|
boxHeight = $box.outerHeight();
|
|
}
|
|
|
|
function onScroll() {
|
|
if ($(window).width() <= 767) {
|
|
$box.removeClass('box_fixed');
|
|
$('#header').css('margin-bottom', 0);
|
|
return;
|
|
}
|
|
|
|
var scrollTop = $(window).scrollTop();
|
|
|
|
if (scrollTop >= boxTop) {
|
|
$box.addClass('box_fixed');
|
|
$('#header').css('margin-bottom', boxHeight);
|
|
} else {
|
|
$box.removeClass('box_fixed');
|
|
$('#header').css('margin-bottom', 0);
|
|
}
|
|
}
|
|
|
|
$(window).on('resize', function () {
|
|
recalc();
|
|
onScroll();
|
|
});
|
|
|
|
$(window).on('scroll', onScroll);
|
|
|
|
recalc();
|
|
onScroll();
|
|
});
|