HEX
Server: Apache
System: Linux vps.rockyroadprinting.net 4.18.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User: rockyroadprintin (1011)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/rockyroadprintin/www/wp-content/themes/consulting/assets/js/stm_anchors_text.js
window.onload = function() {
    var anchor_nav_links = document.querySelectorAll( '.stm_anchors_text__nav a' );
    anchor_nav_links.forEach(function(link){
        link.addEventListener('click', function(e){
            e.preventDefault();
            var id = e.target.href.split("#")[1];
            var block = document.getElementById(id);

            block.scrollIntoView({ behavior: 'smooth' });
        })
    });
}

window.onscroll = function() {
    scrollingCategories( document.querySelectorAll( '.stm_anchors_text__nav a' ) );
}

function scrollingCategories(links) {
    let current_category = links[0].getAttribute('href').substr(1);
    links.forEach(link => {
        const section_id = link.getAttribute('href').substr(1);
        const section = document.getElementById(`${section_id}`);

        if (section.getBoundingClientRect().top < 50) {
            current_category = section_id;
        }

        link.classList.remove('active');
        section.classList.remove('active');
    });

    document.querySelector( `.stm_anchors_text__nav a[href="#${ current_category }"], #${ current_category }`).classList.add('active');
    document.getElementById( `${ current_category }`).classList.add('active');
}