1
0
mirror of https://github.com/Damillora/Yuika synced 2024-11-26 19:07:31 +00:00
Yuika/assets/js/nav-collapse.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-12-26 07:25:58 +00:00
$(document).ready(function () {
$("#menushow").click(function () {
$(".site-header").toggleClass('enabled');
$(".site-header__background").toggleClass('site-header__background--enabled');
$(".menu").toggleClass('enabled');
})
$(".menu__item").click(function () {
$(".site-header").toggleClass('enabled');
$(".site-header__background").toggleClass('site-header__background--enabled');
$(".menu").toggleClass('enabled');
})
var nav = document.querySelector('.site-header');
var feed = document.querySelector('main');
var lastScrollY = window.scrollY;
var lastWindowHeight = window.innerHeight;
var lastDocumentHeight = $(document).height();
var ticking = false;
function onScroll() {
lastScrollY = window.scrollY;
requestTick();
}
function onResize() {
lastWindowHeight = window.innerHeight;
lastDocumentHeight = $(document).height();
requestTick();
}
function requestTick() {
if (!ticking) {
requestAnimationFrame(update);
2020-12-26 07:25:58 +00:00
}
ticking = true;
}
function update() {
var trigger = feed.getBoundingClientRect().top + window.scrollY;
var progressMax = lastDocumentHeight - lastWindowHeight;
// show/hide nav
if (lastScrollY >= nav.getBoundingClientRect().bottom) {
nav.classList.add('detached');
} else {
nav.classList.remove('detached');
}
ticking = false;
}
2020-12-26 07:25:58 +00:00
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onResize, false);
2020-12-26 07:25:58 +00:00
update();
2020-12-26 07:25:58 +00:00
});
2020-12-26 07:25:58 +00:00