简体   繁体   English

如何显示我网站的移动子菜单?

[英]How can I reveal my site's sub-menu for mobile?

I am trying to reveal my sub-menu using jQuery. It is a rewrite of the code in the image using jQuery.我正在尝试使用 jQuery 显示我的子菜单。它是使用 jQuery 重写图像中的代码。

https://github.com/alwayswantedtocode/xpress-cars-web-dev- https://github.com/alwayswantedtocode/xpress-cars-web-dev-

Code I am trying to rewrite using jQuery:我尝试使用 jQuery 重写的代码:

我正在尝试使用 jquery 重写的代码

$(document).on("click", ".navigation", function(event) {

  const target = $(event.target),
    mediaSize = 991;
  homeSubList = $(event.target.parentElement),
    revealSubMenu = $(homeSubList).add('.sub-menu');

  if ($(target).attr("data-toggle") && (window.innerWidth <= mediaSize)) {
    $(homeSubList).toggleClass("active");

    $(revealSubMenu.height()) = $(revealSubMenu).prop('scrollHeight') + 'px';
  };
});

Here it is:这里是:

$(document).on("click",".navigation", function(event){
  const mediaSize = 991;
  if ($(event.target).attr('data-toggle') !== undefined && window.innerWidth <= mediaSize) {
    const menuItemHasChildren = $(event.target).parent();

    $(menuItemHasChildren).addClass('active');
    const subMenu = $(menuItemHasChildren).find('.sub-menu');
    $(subMenu).css('maxHeight', $(subMenu).prop('scrollHeight'));
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM