Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1038412

    I’ve built a page with a Fullwidth Sub Menu (Enfold 4.5), and the menu items are links to anchors in the content below, on the same page.

    I’m able to style the submenu items on :hover, but how can I get the active menu item to be styled differently than the rest (different color and background-color), when the page is scrolled to that anchor point, whether by clicking on the submenu item or just by scrolling? Already tried the following, and no luck:
    Add this in my function.php :

    //One page nav highlight
     
    function activateMenuItem(){
    ?>
    <script>
    
    jQuery(document).scroll(function() {
         var sections = jQuery('.avia-section'),
             menu   = jQuery('.av-submenu-container'),        
             nav_height = menu.outerHeight();
     
    
             jQuery(window).on('scroll', function() {
                var cur_pos = jQuery(this).scrollTop();
                sections.each(function() {
                    var top = jQuery(this).offset().top - 300,
                        bottom = top + jQuery(this).outerHeight();
                    if (cur_pos >= top && cur_pos <= bottom) { 
                        menu.find('li.active-menu-item').toggleClass('active-menu-item');                    
                        menu.find('a[href="https://'+window.location.host+window.location.pathname+'#' + jQuery(this).attr('id') + '"]').parent("li").toggleClass('active-menu-item');
                    }
                });
            });
        });
    </script>
    <?php
    }
    add_action('wp_head', 'activateMenuItem');

    and also this CSS :

    /* Fullwidth Sub Menu - Indicator */
    .av-subnav-menu > li:hover  {
        border-bottom: 2px solid #ed1c23;
    }
    .av-subnav-menu > li.active-menu-item {
        border-bottom: 2px solid #ed1c23;
    }
    

    Thanks in advance.

    #1038473

    Hey makue10,

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #1038517
    This reply has been marked as private.
    #1038952

    Hello again! I sent you a personal message with login and I wanted to make sure you saw it.

    #1039896

    Hi,

    Thank you for writing to us.

    Let me share an example link which shows the submenu highlight feature in action.

    To achieve this modification please refer to the documentation

    Let us know if you need any help!

    Best regards,
    Vinay

    #1040196

    Thanks a lot for the help. My misunderstanding was the custom css class.

    #1040331

    Hi,

    Great, glad you got it working. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.