GravTheme/js/base.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-09-15 12:28:31 +00:00
let mobileMenuState = false;
$(function() {
let height = $('#imHeader').height();
let stickyBar = $('#imStickyBarContainer');
let topButton = $('#to-top');
let stickyHeight = stickyBar.height();
$(window).on('scroll', {passive: true}, function(event) {
if(mobileMenuState) {
return;
}
if(window.scrollY > height) {
stickyBar.css('visibility', 'visible');
stickyBar.css('top', '0');
stickyBar.addClass('scroll-sticky');
topButton.removeClass('imHidden');
}
else {
stickyBar.css('top', '-' + stickyHeight + "px");
stickyBar.removeClass('scroll-sticky');
topButton.addClass('imHidden');
}
});
$('.hamburger-component').on('click', function(event) {
mobileMenuState = !mobileMenuState;
let bar = $('#imStickyBarContainer');
bar.css('visibility', bar.css('visibility') == 'hidden' ? 'visible' : 'hidden');
$('#nav-sticky-container > ul').toggleClass('hidden');
$('#imPageExtContainer').toggleClass('darken');
});
$('#to-top-link').on('click', function(event) {
event.preventDefault();
let target = this.hash;
$('html').animate({
'scrollTop': $('#imGoToCont').offset().top
}, 900, 'swing', function() {
window.location.hash = target;
});
});
});