Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1378912

    Have a look at https://fyrholtrejser.dk/rejser/test/ where you see the Sticky Submenu in action.
    I am controlling the font size in this menu with the following CSS:
    #top .av-subnav-menu li a {
    font-size: 17px;
    }
    But how do I make the active menu item underlined – or highlighted – in this Sticky Submenu?

    Thank you for a great support in this forum :-)

    #1378918

    Hey,

    Thanks for contacting us!

    Please refer to this post – https://kriesi.at/support/topic/active-submenu-highlight/ :)

    Regards,
    Yigit

    #1378943

    Thank you for getting back to me this fast… :-)
    I want the Sticky Submenu to underline the active menu item.
    I have added this PHP Snippet:
    ————————————————————————
    // Highlight one page nav

    function activateMenuItem(){
    ?>
    <script>
    jQuery(document).scroll(function() {
    var sections = jQuery(‘.iconbox’),
    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’).removeClass(‘active-menu-item’);
    menu.find(‘a[href=”#’ + jQuery(this).attr(‘id’) + ‘”]’).parent(‘li’).addClass(‘active-menu-item’);
    }
    });
    });
    });

    </script>
    <?php
    }
    add_action(‘wp_head’, ‘activateMenuItem’);
    ————————————————————————
    And this CSS:
    #top .av-submenu-container .active-menu-item,
    #top .av-submenu-container .active-menu-item a {
    text-decoration: underline !important;
    }

    But still no underlined active item.
    The menu items are set as “Button Style (Colored)” and I did try the “Default Style” in case the problem lays here. But nope…

    #1388008

    Hi,

    Did you add the code in the functions.php file? Please remove the previous code and use the script that we provided in the following links instead.

    // https://kriesi.at/support/topic/full-width-submenu-4/#post-1297063
    // https://kriesi.at/support/topic/enfold-gaming-demo-menu-functionality-on-sub-menu/#post-1284777

    Best regards,
    Ismael

    #1388022

    Thank you Ismael.
    The links just leads to more confusion but I did try and follow the conclusions there.
    Status now is that, since I don’t have a Child Theme, I put the following code in the functions.php using the plugin “Code Snippets”. The plugin works with other issues regarding the functions.php file, so I would expect it to work fine also in this case.
    ————————————————————————————
    // a custom script
    // add current-menu-item class to active item
    function ava_custom_script_mod() {
    if ( wp_script_is( ‘avia-default’, ‘registered’ ) ) {
    wp_add_inline_script( ‘avia-default’, ‘
    (function($) {
    $(document).ready(function() {
    const setActive = (entry) => {
    let item = $(#top .av-subnav-menu a[href*=\'+ entry + \']);

    if(!item.attr(“href”).includes(entry)) return;

    let list = item.parent(“li”);
    let parent = list.parent(“#menu-sub-menu”);

    if(list.is(“.current-menu-item”)) return;

    parent.find(“li”).removeClass(“current-menu-item”);
    list.addClass(“current-menu-item”);
    }

    const createObserver = (entry) => {
    let el = document.querySelector(entry);

    const observer = new IntersectionObserver(function(entries) {
    if(entries[0].isIntersecting === true) {
    setActive(entry);
    }

    }, { root: null, threshold: [0.1] });

    observer.observe(el);
    }

    const anchors = [“#dagsprogram”, “#grad”, “#praktisk”, “#indkvartering”, “#prisinformation”];

    anchors.map(anchor => {
    createObserver(anchor);
    });
    });
    })(jQuery);
    ‘);
    }
    }
    add_action( ‘wp_enqueue_scripts’, ‘ava_custom_script_mod’, 9999);
    ———————————————————————————————-

    In Quick CSS I put this:
    #top .av-subnav-menu > li.current-menu-item a {
    color: red !important;
    text-decoration: underline !important;
    }
    ———————————————————————————————-
    The “Full Width Sub Menu” does not go in a Color Section. So let’s not go down that road…

    In the Full Width Sub Menu I did not add anything under Developer Settings.

    The goal is simple: I want the active item to be underlined with a white line in the Sticky Submenu.

    Please login and have a look. And advice what to do next. What am I missing here?

    Thank you for a great support.

    #1388034

    Hi,

    Thank you for the update.

    We logged in and modified the code a bit. It is working correctly now.

    // a custom script
    // add current-menu-item class to active item
    function ava_custom_script_mod() {
        if ( wp_script_is( 'avia-default', 'registered' ) ) {
            wp_add_inline_script( 'avia-default', '
    		(function($) {
    			$(document).ready(function() {
    				const setActive = (entry) => {     
    					$("#top .av-subnav-menu a").parent("li").removeClass("current-menu-item");
    					let item = $("#top .av-subnav-menu a[href*=" + entry + "]");
    
    					if(!item.attr("href").includes(entry)) return;
    
    					let list = item.parent("li");
    					let parent = list.parent("#menu-sub-menu");
    
    					if(list.is(".current-menu-item")) return;
    
    					parent.find("li").removeClass("current-menu-item");
    					list.addClass("current-menu-item");
    				}
    
    				const createObserver = (entry) => {
    					let el = document.querySelector(entry);
    
    					const observer = new IntersectionObserver(function(entries) {    
    						if(entries[0].isIntersecting === true) {
    							setActive(entry);
    						}
    
    						}, { root: null, threshold:  [0.1] });
    
    					observer.observe(el);
    				}
    
    				const anchors = ["#dagsprogram", "#grad", "#praktisk", "#indkvartering", "#prisinformation"];
    
    				anchors.map(anchor => {
    					createObserver(anchor);
    				});
    			});
    		})(jQuery);
    	');
        }
     }
     add_action( 'wp_enqueue_scripts', 'ava_custom_script_mod', 9999);
    

    Best regards,
    Ismael

    #1388066

    Wow, thank you very much – you’re the man! :-)
    Did you notice that the wrong anchor link is sometimes underlined/highlighted in the sticky submenu? Maybe it has something to do with the fact that two anchor elements are visible at the same time and the sticky submenu is confused on which link to underline…?
    Or should I place the anchors differently maybe?

    #1393862

    Hi,

    Thank you for following up.

    We did notice the issue, but it seems to only happen on the last two sections or anchors. You may need to add more content to the other section so that they don’t intersect with the other.

    Best regards,
    Ismael

    #1393876

    You are correct – the problem is NOT there if I make the browser window a lot smaller.
    Is there not a work around this issue? I can’t really just add more content to the anchor sections – just for the purpose of making the link underline work correctly.
    Crossing my fingers :-) And thank you again for helping out here…

    #1393893

    Hi,

    In the following line, try to adjust the threshold value from 0.1 to 0.3 or 0.5.

    { root: null, threshold:  [0.1] });
    

    Make sure to purge the cache before testing the page.

    { root: null, threshold:  [0.5] });
    

    or

    { root: null, threshold:  [0.3] });
    

    Best regards,
    Ismael

    #1393982

    Unfortunately, it makes no difference… And I did try with many other values but no luck…
    Any other ideas?
    I would really love for this feature to work smoothly.

    #1394495

    Hi,

    The changes seem to be working correctly on my end, checking it on a 1080p monitor. What is the screen resolution of your monitor? We adjusted the threshold to 0.9. This should apply the active state to the menu item only when 90% of the corresponding section is visible in the browser. Please make sure to purge the cache before testing the page.

    Best regards,
    Ismael

    #1394850

    Thank you – it’s all working just fine now that I have put some more content around the anchor elements.
    You can close this thread now.
    Great support :-)

    #1394892

    Hi,

    Great! Let us know if there is anything else we can help you with.

    Have a nice day.

    Best regards,
    Ismael

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Sticky Submenu with underlined active item’ is closed to new replies.