fix main > article pointer event
This commit is contained in:
parent
7cda66f837
commit
9aee1ad5b5
3 changed files with 47 additions and 23 deletions
64
assets/dist/script.js
vendored
64
assets/dist/script.js
vendored
|
|
@ -8,16 +8,37 @@ function getUnit(id) {
|
|||
var pxUnit = remUnit * remFactor;
|
||||
return pxUnit;
|
||||
}
|
||||
function throttle(callback, limit) {
|
||||
var 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 later() {
|
||||
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;
|
||||
};
|
||||
}
|
||||
function setWindowHeightFactor() {
|
||||
|
|
@ -39,6 +60,13 @@ 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() {
|
||||
var footnotes = document.querySelectorAll('a[href^="#sdfootnote"]');
|
||||
footnotes.forEach(function (footnote) {
|
||||
|
|
@ -63,17 +91,6 @@ function removeAccents(str) {
|
|||
function slugify(str) {
|
||||
return removeAccents(str.toLowerCase());
|
||||
}
|
||||
var subscribeBtn = document.querySelector("#subscribe-btn");
|
||||
function showSubscribeField(event) {
|
||||
event.preventDefault();
|
||||
var button = event.target;
|
||||
var li = button.parentNode;
|
||||
var form = li.querySelector("#subscribe-form");
|
||||
var input = form.querySelector("input");
|
||||
form.classList.remove("hidden");
|
||||
button.classList.add("hidden");
|
||||
input.focus();
|
||||
}
|
||||
function subscribe(event) {
|
||||
event.preventDefault();
|
||||
var email = document.querySelector("#subscribe-form input");
|
||||
|
|
@ -101,9 +118,13 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
window.window.scrollTo({
|
||||
top: 0
|
||||
});
|
||||
window.addEventListener("scroll", function () {
|
||||
var handleScroll = throttle(function () {
|
||||
toggleLogoState();
|
||||
});
|
||||
if (window.innerWidth <= 680) {
|
||||
toggleFooterState();
|
||||
}
|
||||
}, 100);
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
setWindowHeightFactor();
|
||||
window.addEventListener("resize", function () {
|
||||
setWindowHeightFactor();
|
||||
|
|
@ -153,5 +174,4 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
navOverlay.addEventListener("click", function () {
|
||||
closeNav();
|
||||
});
|
||||
subscribeBtn.addEventListener("click", showSubscribeField);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue