Created
March 12, 2026 08:22
-
-
Save jmabbas/01fa992179cbec75e17f4244712e51a5 to your computer and use it in GitHub Desktop.
Electro - Department menu vertical scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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