improve mobile footer
This commit is contained in:
parent
af1ffe78c6
commit
5252d51633
5 changed files with 97 additions and 59 deletions
|
|
@ -9,16 +9,36 @@ function getUnit(id) {
|
|||
return pxUnit;
|
||||
}
|
||||
|
||||
function throttle(callback, limit) {
|
||||
let waiting = false;
|
||||
// Throttle found here : https://gist.github.com/ionurboz/51b505ee3281cd713747b4a84d69f434
|
||||
function throttle(func, wait, options) {
|
||||
var context, args, result;
|
||||
var timeout = null;
|
||||
var previous = 0;
|
||||
if (!options) options = {};
|
||||
var later = function () {
|
||||
previous = options.leading === false ? 0 : Date.now();
|
||||
timeout = null;
|
||||
result = func.apply(context, args);
|
||||
if (!timeout) context = args = null;
|
||||
};
|
||||
return function () {
|
||||
if (!waiting) {
|
||||
callback.apply(this, arguments);
|
||||
waiting = true;
|
||||
setTimeout(function () {
|
||||
waiting = false;
|
||||
}, limit);
|
||||
var now = Date.now();
|
||||
if (!previous && options.leading === false) previous = now;
|
||||
var remaining = wait - (now - previous);
|
||||
context = this;
|
||||
args = arguments;
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
previous = now;
|
||||
result = func.apply(context, args);
|
||||
if (!timeout) context = args = null;
|
||||
} else if (!timeout && options.trailing !== false) {
|
||||
timeout = setTimeout(later, remaining);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +67,17 @@ function toggleLogoState() {
|
|||
document.querySelector("#main-header").classList.remove("minimized");
|
||||
}
|
||||
}
|
||||
function toggleFooterState() {
|
||||
if (scrollY > 90) {
|
||||
document
|
||||
.querySelector("#main-footer")
|
||||
.classList.add("main-footer--background");
|
||||
} else {
|
||||
document
|
||||
.querySelector("#main-footer")
|
||||
.classList.remove("main-footer--background");
|
||||
}
|
||||
}
|
||||
|
||||
function fixFootNotes() {
|
||||
const footnotes = document.querySelectorAll('a[href^="#sdfootnote"]');
|
||||
|
|
@ -108,9 +139,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
top: 0,
|
||||
});
|
||||
|
||||
window.addEventListener("scroll", () => {
|
||||
const handleScroll = throttle(() => {
|
||||
toggleLogoState();
|
||||
});
|
||||
if (window.innerWidth <= 680) {
|
||||
toggleFooterState();
|
||||
}
|
||||
}, 100);
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
|
||||
setWindowHeightFactor();
|
||||
window.addEventListener("resize", () => {
|
||||
|
|
@ -168,6 +203,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
navOverlay.addEventListener("click", () => {
|
||||
closeNav();
|
||||
});
|
||||
|
||||
subscribeBtn.addEventListener("click", showSubscribeField);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue