mirror of
https://github.com/Damillora/Yuika
synced 2024-11-22 01:07:32 +00:00
chore: Put the menu handlers on the ready block
This commit is contained in:
parent
2fc9c06324
commit
bcf0b2eef3
@ -1,61 +1,62 @@
|
||||
$("#menushow").click(function(){
|
||||
$(".site-header").toggleClass('enabled');
|
||||
$(".site-header__background").toggleClass('site-header__background--enabled');
|
||||
$(".menu").toggleClass('enabled');
|
||||
})
|
||||
$(".nav li").click(function(){
|
||||
$(".site-header").toggleClass('enabled');
|
||||
$(".site-header__background").toggleClass('site-header__background--enabled');
|
||||
$(".menu").toggleClass('enabled');
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
var nav = document.querySelector('.site-header');
|
||||
var feed = document.querySelector('main');
|
||||
$("#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 lastScrollY = window.scrollY;
|
||||
var lastWindowHeight = window.innerHeight;
|
||||
var lastDocumentHeight = $(document).height();
|
||||
var ticking = false;
|
||||
var nav = document.querySelector('.site-header');
|
||||
var feed = document.querySelector('main');
|
||||
|
||||
function onScroll() {
|
||||
lastScrollY = window.scrollY;
|
||||
requestTick();
|
||||
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);
|
||||
}
|
||||
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');
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
lastWindowHeight = window.innerHeight;
|
||||
lastDocumentHeight = $(document).height();
|
||||
requestTick();
|
||||
}
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
function requestTick() {
|
||||
if (!ticking) {
|
||||
requestAnimationFrame(update);
|
||||
}
|
||||
ticking = true;
|
||||
}
|
||||
window.addEventListener('scroll', onScroll, { passive: true });
|
||||
window.addEventListener('resize', onResize, false);
|
||||
|
||||
function update() {
|
||||
var trigger = feed.getBoundingClientRect().top + window.scrollY;
|
||||
var progressMax = lastDocumentHeight - lastWindowHeight;
|
||||
update();
|
||||
|
||||
// show/hide nav
|
||||
if (lastScrollY >= nav.getBoundingClientRect().bottom) {
|
||||
nav.classList.add('detached');
|
||||
} else {
|
||||
nav.classList.remove('detached');
|
||||
}
|
||||
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', onScroll, { passive: true });
|
||||
window.addEventListener('resize', onResize, false);
|
||||
|
||||
update();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user