-
AuthorPosts
-
July 14, 2023 at 6:23 pm #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, 4 months ago by maxgorelkine.
July 17, 2023 at 10:49 am #1413468I 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');
July 17, 2023 at 11:48 am #1413473hm 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.July 20, 2023 at 4:52 pm #1413847 -
AuthorPosts
- You must be logged in to reply to this topic.