PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / sticky-header / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/sticky-header/frontend.js

53 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 document.querySelectorAll('.bkbg-sth-header[data-sticky]').forEach(function (header) {
5 var isSticky = header.dataset.sticky === '1';
6 var shouldShrink = header.dataset.shrink === '1';
7
8 if (!isSticky) return;
9
10 var lastScrollY = 0;
11
12 function handleScroll() {
13 var scrollY = window.scrollY || window.pageYOffset;
14 var isScrolled = scrollY > 10;
15
16 if (isScrolled) {
17 header.classList.add('bkbg-sth-is-scrolled');
18 } else {
19 header.classList.remove('bkbg-sth-is-scrolled');
20 }
21
22 if (shouldShrink && isScrolled) {
23 header.classList.add('bkbg-sth-shrunk');
24 } else {
25 header.classList.remove('bkbg-sth-shrunk');
26 }
27
28 lastScrollY = scrollY;
29 }
30
31 window.addEventListener('scroll', handleScroll, { passive: true });
32 handleScroll(); // init state
33
34 /* ---- Mobile menu toggle ---- */
35 var hamburger = header.querySelector('.bkbg-sth-hamburger');
36 var mobileNav = header.querySelector('.bkbg-sth-mobile-nav');
37
38 if (hamburger && mobileNav) {
39 hamburger.addEventListener('click', function () {
40 var expanded = hamburger.getAttribute('aria-expanded') === 'true';
41 hamburger.setAttribute('aria-expanded', String(!expanded));
42 mobileNav.setAttribute('aria-hidden', String(expanded));
43
44 if (!expanded) {
45 mobileNav.removeAttribute('style');
46 } else {
47 mobileNav.style.display = 'none';
48 }
49 });
50 }
51 });
52 })();
53