• Hi there,

    I’ve received immense support here and I’m very grateful. So thank you. One of the forum mods helped me out with making child menu items collapse into parent ones. It’s great. There seems to be one little bug with the theme cooperating with this awesome javascript code.

    Here’s the code I got:

    /* Your code goes here */ 
    
    var $ = jQuery,
        breakpoint = 940,
        initClass = 'toggleSubnavInitiated',
        menu,
        parentLinks,
        childrenItems;
    
    $(document).ready(function() {
        menu = $('.menu');
        parentLinks = menu.find('.menu-item-has-children > a');
        childrenItems = menu.find('.sub-menu');
    
        if ($(window).width() <= breakpoint) {
            toggleSubnav(menu, parentLinks, childrenItems);
        }
    });
    
    $(window).resize(function() {
    
        if ($(window).width() <= breakpoint) {
            toggleSubnav(menu, parentLinks, childrenItems);
        }
    });
    
    function toggleSubnav(menu, parentLinks, childrenItems) {
    
        if (parentLinks.length !== 0) {
            menu.addClass(initClass);
            childrenItems.hide();
    
            parentLinks.on('click', function(event) {
                event.preventDefault();
    
                $(this).siblings('.sub-menu').toggle();
            });
        }
    }

    The theme developer said what I probably need to add is a “resize event?” They weren’t able to provide assistance only because it’s outside the scope of the support they provide, which I totally get. They did mention that the script should be wrapped inside this resize event so when the window is resized, the script is fired? I googled around and I found this Javascript resize event code: object.onresize=function(){myScript}; Does anyone know if it’s as simple as plugging this code in at the top (or bottom) or do I need to include squiggly brackets? :S Thanks everyone for your help. 😛

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter andrewf12

    (@andrewf12)

    So apparently, the script works fine going from desktop to mobile with the breakpoint of 940 px, but what’s missing is going from mobile to desktop with a breakpoint of 941 px? Anyone have any solutions? 😛

    Thanks, everyone.

    Thread Starter andrewf12

    (@andrewf12)

    I imagine it is not as simple as just copying the script and adding a breakpoint of 941 px

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Catch Flames] Add resize event to script?’ is closed to new replies.