Skip to content

Instantly share code, notes, and snippets.

@jmabbas
Created March 12, 2026 08:22
Show Gist options
  • Select an option

  • Save jmabbas/01fa992179cbec75e17f4244712e51a5 to your computer and use it in GitHub Desktop.

Select an option

Save jmabbas/01fa992179cbec75e17f4244712e51a5 to your computer and use it in GitHub Desktop.
Electro - Department menu vertical scroll
add_action( 'wp_head', 'ec_child_department_menu_vertical_scroll', 10 );
function ec_child_department_menu_vertical_scroll() { ?>
<script>
document.addEventListener("DOMContentLoaded", function () {
const ul = document.getElementById("menu-all-departments-menu-1");
if (!ul) return;
const visibleCount = 10;
const lis = Array.from(ul.querySelectorAll(":scope > li"));
let startIndex = 0;
function renderMenu() {
lis.forEach((li, index) => {
if (index >= startIndex && index < startIndex + visibleCount) {
li.style.display = "block";
} else {
li.style.display = "none";
}
});
}
renderMenu();
ul.addEventListener("wheel", function (e) {
e.preventDefault();
if (e.deltaY > 0) {
if (startIndex + visibleCount < lis.length) {
startIndex++;
renderMenu();
}
} else {
if (startIndex > 0) {
startIndex--;
renderMenu();
}
}
}, { passive: false });
});
</script>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment