feat: migrate Hugo Bootstrap theme to latest Hugo with Tailwind CSS and refactor codebase
* replace Bootstrap-based styling with Tailwind CSS * update theme compatibility for latest Hugo version * refactor templates and partials * fix outdated code and broken components * improve project structure and maintainability * optimize styling and frontend build setup
This commit is contained in:
43
assets/js/main.js
Executable file
43
assets/js/main.js
Executable file
@@ -0,0 +1,43 @@
|
||||
// main script
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
// Header shrink on scroll
|
||||
(function () {
|
||||
var header = document.getElementById("site-header");
|
||||
if (!header) return;
|
||||
// only enable shrink behavior when navbar_fixed param is true
|
||||
var navbarFixed = header.dataset && header.dataset.navbarFixed === "true";
|
||||
if (!navbarFixed) return;
|
||||
var lastKnownScrollY = 0;
|
||||
var ticking = false;
|
||||
var threshold = 20;
|
||||
|
||||
function onScroll() {
|
||||
lastKnownScrollY = window.scrollY || window.pageYOffset;
|
||||
requestTick();
|
||||
}
|
||||
|
||||
function requestTick() {
|
||||
if (!ticking) {
|
||||
requestAnimationFrame(update);
|
||||
}
|
||||
ticking = true;
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (lastKnownScrollY > threshold) {
|
||||
header.classList.add("py-2", "lg:py-3", "shadow-lg");
|
||||
header.classList.remove("py-6", "lg:py-6");
|
||||
} else {
|
||||
header.classList.remove("py-2", "lg:py-3", "shadow-lg");
|
||||
header.classList.add("py-6", "lg:py-6");
|
||||
}
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
window.addEventListener("scroll", onScroll, { passive: true });
|
||||
// run on init
|
||||
update();
|
||||
})();
|
||||
})();
|
||||
Reference in New Issue
Block a user