Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1413316

    Hi, I need to display the header widget (added with your official method) inside the burger menu on screen width less than 990px.

    I found this post that makes it happen, thanks to @Guenni007 solution, but unfortunately some bugs appear:

    • When I click on a mega link in the main menu on desktop, the widget disappears
    • When manually reducing the screen size, clicking on the burger menu, then enlarging the browser size again, the desktop widget doesn’t appear without reloading the page

    I think it’s because the detaching and appending of the widget happens when clicking on a link.
    Wouldn’t it be better to make the switch depending on screen size and not a click ? So for instance if ($(window).width() <= 990){ then append the widget to burger menu, and if ($(window).width() > 990){ then append the widget to header.

    Unfortunately I’m not sure how to adapt the code to make it work… could you help ?
    Thanks in advance!

    • This topic was modified 1 year, 1 month ago by maxgorelkine.
    #1413468

    I think I found a way :) :

    function move_header_widget_to_burger() {
    ?>
    <script>
    (function($){
    	var isMobile = false; // Variable pour stocker l'état initial de l'écran
    
    	function moveWidget() {
    		if (isMobile && $(window).width() > 990) {
    			// Réinitialise le widget si l'écran est plus large que 990px
    			$('#header_main .widget').css('display', 'block');
    			$('.av-burger-overlay-inner .widget').detach().appendTo('#header_main .inner-container').removeAttr('style');
    			isMobile = false; // Met à jour l'état de l'écran
    		} else if (!isMobile && $(window).width() <= 990) {
    			// Déplace le widget dans le menu burger si l'écran est inférieur ou égal à 990px
    			$('#header_main .widget').css('display', 'none');
    			$('#header').one('click', '.av-main-nav-wrap', function() {
    				$('#top #av-burger-menu-ul').css({
    					'display' : 'block',
    					'height' : 'auto',
    					'vertical-align' : 'top',
    					'padding' : '140px 0 0',
    				});
    				var burger_widget = $('#header_main .widget').detach();
    				burger_widget.appendTo('.av-burger-overlay-inner').css({
    					'display' : 'block',
    					'position': 'relative',
    					'width': '94%',
    					'text-align': 'left',
    					'margin-left': '3%',
    					'border-top': '1px dashed #333',
    				});
    			});
    			isMobile = true; // Met à jour l'état de l'écran
    		}
    	}
    
    	$(window).on('resize', moveWidget); // Appelle la fonction lors du redimensionnement de la fenêtre
    
    	moveWidget(); // Appelle la fonction au chargement de la page
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'move_header_widget_to_burger');
    #1413473

    hm i changed my test page to have a mega-menu on demos ( https://pureinstall.webers-testseite.de/ )
    but the widget is still inside the hamburger even if i click first on a mega-menu-item.

    #1413847

    Hi,
    maxgorelkine glad to hear that you have sorted this out, shall we close this thread then?

    Best regards,
    Mike

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