Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1489933

    Hi Enfold,
    as far as I understand the design of the Table of Contents widget area (line from beginning to end with a colored circle on it), it should show the current position of the reader. When the reader clicks on a headline this headline should be highlighted. If this the expected behavior? If it is, how can I fix it? I shared a private example page.

    Also by default the headline of the table of contents is h3. How can I change that (to h2 or to remove the h-tag completely?

    Thanks

    • This topic was modified 1 day, 9 hours ago by atx_m.
    #1489945

    Hey atx_m,

    Thank you for the inquiry.

    The TOC widget doesn’t have an active state by default, but you can use this script in the functions.php file to add an active class on click and while scrolling.

    add_action('wp_footer', function () {
        ?>
        <script>
        document.addEventListener("DOMContentLoaded", function () {
          const tocLinks = document.querySelectorAll('.avia-toc-link');
          const headingSelectors = document.querySelector('.avia-toc-container').dataset.level.split(',');
          const headings = Array.from(document.querySelectorAll(headingSelectors.join(',')));
    
          tocLinks.forEach(link => {
            link.addEventListener('click', function () {
              tocLinks.forEach(l => l.classList.remove('active'));
              this.classList.add('active');
            });
          });
    
          function onScroll() {
            let scrollPosition = window.scrollY + 100;
            let currentId = null;
    
            for (let i = headings.length - 1; i >= 0; i--) {
              const heading = headings[i];
              if (heading.offsetTop <= scrollPosition) {
                currentId = heading.id;
                break;
              }
            }
    
            if (currentId) {
              tocLinks.forEach(link => {
                link.classList.toggle('active', link.getAttribute('href') === #${currentId});
              });
            }
          }
    
          window.addEventListener('scroll', onScroll);
          onScroll();
        });
        </script>
        <?php
    }, 9999);
    

    You can then include this css to adjust the color of the active TOC links:

    .avia-toc-link.active {
      color: #fe9000;
      font-weight: bold;
    }

    To change the heading tags, edit the widget and look for the “Select headlines to include” option.

    Let us know the result.

    Best regards,
    Ismael

    #1489950

    I added both codes but I can’t see any change on the blog Post.
    Is this correct ?
    wp_footer
    since it is the sidebar, not the footer?

    How can I change the font color and ensure that not only capital letters are used?

    • This reply was modified 15 hours, 1 minute ago by atx_m.
    • This reply was modified 8 hours, 52 minutes ago by atx_m.
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.