PageSourceSearch

https://high-cloud.ru/assets/js/page-nav.js

js high-cloud.ru collected 2026-10-06 07:08:35 UTC 2,961 bytes, 64 lines download raw bytes

1        (function() {
2            // Находим все ссылки и соответствующие секции
3            const links = document.querySelectorAll('.page-nav a');
4            const sections = Array.from(links).map(link => {
5                const id = link.getAttribute('href');
6                return id ? document.querySelector(id) : null;
7            }).filter(Boolean);
8
9            if (sections.length === 0) return;
10
11            const OFFSET = 75; // отступ для плавной прокрутки (если есть фиксированная шапка)
12
13            // Определение активной секции по положению скролла
14            function setActive() {
15                const scrollPos = window.scrollY + OFFSET;
16                let activeIndex = -1;
17                // Ищем последнюю секцию, чей верх не выше scrollPos
18                for (let i = 0; i < sections.length; i++) {
19                    if (sections[i].offsetTop <= scrollPos) {
20                        activeIndex = i;
21                    } else {
22                        break;
23                    }
24                }
25                // Устанавливаем активный класс
26                links.forEach((link, idx) => {
27                    if (idx === activeIndex) {
28                        link.classList.add('active');
29                    } else {
30                        link.classList.remove('active');
31                    }
32                });
33            }
34
35            // Обработчик скролла с requestAnimationFrame для плавности
36            let ticking = false;
37            window.addEventListener('scroll', () => {
38                if (!ticking) {
39                    requestAnimationFrame(() => {
40                        setActive();
41                        ticking = false;
42                    });
43                    ticking = true;
44                }
45            });
46
47            // Плавная прокрутка при клике
48            links.forEach(link => {
49                link.addEventListener('click', (e) => {
50                    e.preventDefault();
51                    const targetId = link.getAttribute('href');
52                    const target = targetId ? document.querySelector(targetId) : null;
53                    if (!target) return;
54                    const targetPosition = target.offsetTop - OFFSET;
55                    window.scrollTo({ top: targetPosition, behavior: 'smooth' });
56                    // Мгновенно подсвечиваем выбранный пункт
57                    links.forEach(l => l.classList.remove('active'));
58                    link.classList.add('active');
59                });
60            });
61
62            // Запускаем при загрузке
63            setActive();
64        })();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.