# blockenberg/2.0.7/blocks/sticky-header/frontend.js

Blockenberg — 600+ Advanced Gutenberg Blocks &amp; AI Agent for WordPress Block Editor, version 2.0.7. 53 lines.

- Page: https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/sticky-header/frontend.js
- Raw: https://pluginprobe.com/plugins/blockenberg/2.0.7/raw/blocks/sticky-header/frontend.js
- Modified: 2026-03-06T12:32:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/sticky-header/frontend.js#L10-L20`.

```javascript
(function () {
    'use strict';

    document.querySelectorAll('.bkbg-sth-header[data-sticky]').forEach(function (header) {
        var isSticky = header.dataset.sticky === '1';
        var shouldShrink = header.dataset.shrink === '1';

        if (!isSticky) return;

        var lastScrollY = 0;

        function handleScroll() {
            var scrollY = window.scrollY || window.pageYOffset;
            var isScrolled = scrollY > 10;

            if (isScrolled) {
                header.classList.add('bkbg-sth-is-scrolled');
            } else {
                header.classList.remove('bkbg-sth-is-scrolled');
            }

            if (shouldShrink && isScrolled) {
                header.classList.add('bkbg-sth-shrunk');
            } else {
                header.classList.remove('bkbg-sth-shrunk');
            }

            lastScrollY = scrollY;
        }

        window.addEventListener('scroll', handleScroll, { passive: true });
        handleScroll(); // init state

        /* ---- Mobile menu toggle ---- */
        var hamburger = header.querySelector('.bkbg-sth-hamburger');
        var mobileNav = header.querySelector('.bkbg-sth-mobile-nav');

        if (hamburger && mobileNav) {
            hamburger.addEventListener('click', function () {
                var expanded = hamburger.getAttribute('aria-expanded') === 'true';
                hamburger.setAttribute('aria-expanded', String(!expanded));
                mobileNav.setAttribute('aria-hidden', String(expanded));

                if (!expanded) {
                    mobileNav.removeAttribute('style');
                } else {
                    mobileNav.style.display = 'none';
                }
            });
        }
    });
})();

```
