【问题标题】:GRT Fixed Responsive Menu - jQuery Plugin - problem with closing menu (after click the link)GRT 修复了响应式菜单 - jQuery 插件 - 关闭菜单的问题(点击链接后)
【发布时间】:2020-11-11 13:52:06
【问题描述】:

您好,我在关闭移动菜单时遇到问题 - 我使用 jQuery 插件在我的网站上实现了该功能:https://www.jqueryscript.net/menu/Sticky-Mobile-Navigation-GRT-Responsive-Menu.html。

当我点击菜单内的链接时,它仍然处于打开状态 - 它会转到该部分,但菜单并未关闭。 我需要关于使用什么 JS 函数来在单击相应链接后能够自动关闭菜单的帮助。

在我的代码下面:

(function( $ ){
$.fn.grtmobile = function () {
    if ($(window).width() < 992) {
        $('.grt-mobile-button').on('click', function(){
            $(this).toggleClass("grt-mobile-button-open");
            $("ul.grt-menu").toggleClass("open-grt-menu ");
        });
    }
}})( jQuery );

我将不胜感激任何我应该添加以使其工作的帮助

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    应用下面的代码后,我能够解决这个问题 - 现在它可以工作了,但有时“汉堡”会消失,而且图标并不总是返回到初始状态

    (function( $ ){
    $.fn.grtmobile = function () {
        if ($(window).width() < 992) {
            $('.grt-mobile-button').on('click', function(){
                $(this).toggleClass("grt-mobile-button-open");
                $("ul.grt-menu").toggleClass("open-grt-menu ");
            });
            $('a').on('click', function(){
                $('.grt-mobile-button').parent().removeClass("grt-mobile-button-open");
                $("ul.grt-menu").removeClass("open-grt-menu");
              });
        }
    }
    

    })( jQuery )

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多