• Resolved mapsmarketing

    (@mapsmarketing)


    There doesn’t seem to be a simple JS check whether a megamenu panel is outside of the window boundaries.

    It should have 3 conditions: offset left, offset right and offset both sides. If it’s offset on the left, then the megamenu should display on the right. If it’s offset on the right, then the megamenu should display on the left. If the megamenu cannot fit on either side, then align it to the middle of the menu item.

    *JS:*

    (function($) {
    
        $(window).on( 'elementor/frontend/init', function() {
    
            $(window).on('load', function() {
                $('.elementskit-megamenu-panel').each(function() {
                    $(this).css({
                        'left': 'auto',
                        'right': 0,
                        'transform': 'none'
                    });
    
                    megaMenuOffScreen( $(this) );
                });
            });
    
        });
    
        function megaMenuOffScreen( $this ) {
            let viewport = $(window).width();
            let offsetLeft = $this.offset().left;
            let offsetRight = $this.offset().left + $this.width();
    
            if ( offsetLeft < 0 ) {
                $this.css({
                    'left': 0,
                    'right': 'auto',
                    'transform': 'none'
                });
    
                offsetRight = $this.offset().left + $this.width();
    
                if ( offsetRight > $(window).width() ) {
                    $this.css({
                        'left': '50%',
                        'right': 'auto',
                        'transform': 'translateX(-50%)'
                    });
                }
            }
    
            if ( offsetRight > $(window).width() ) {
                $this.css({
                    'left': 'auto',
                    'right': 0,
                    'transform': 'none'
                });
    
                offsetLeft = $this.offset().left;
    
                if ( offsetLeft < 0 ) {
                    $this.css({
                        'left': '50%',
                        'right': 'auto',
                        'transform': 'translateX(-50%)'
                    });
                }
            }
        }
    
    })(jQuery);

    *Megamenu settings:*
    – Custom width: 800px
    – Mega Menu Position as: Relative

Viewing 1 replies (of 1 total)
  • Hello @mapsmarketing ,
    Thanks for reaching out to us. Sincerely apologize for the delay in responding.

    Thanks for sharing a solution but sorry to inform you that the problem related to this solution or Megamenu is not clear yet. Can you please share more details about the problem first? If you can share a screenshot or a video, the issue will become easier to understand.

    I will check everything properly and if I’m able to trace any issue with the Megamenu, will evaluate the solution and take further steps to resolve the issue ASAP!

    Looking forward to your valuable response.

    Best Regards,
    Prosenjit

Viewing 1 replies (of 1 total)
  • The topic ‘MegaMenu going off screen’ is closed to new replies.