简体   繁体   English

Javascript 菜单切换在上线后无法在移动设备上运行

[英]Javascript menu toggle not working on mobile devices after going live

I have a page that toggles a menu when clicked on the menu anchor.我有一个页面可以在单击菜单锚点时切换菜单。 It is working well from mobile devices when hosted locally on xamp server, but just displays # when it is on the production server.在 xamp 服务器上本地托管时,它在移动设备上运行良好,但在生产服务器上时仅显示 #。 Still, it works when I resized desktop window size, but not on my mobile.尽管如此,当我调整桌面 window 大小时它仍然有效,但在我的手机上却不行。 Here is my link to toggle a menu这是我切换菜单的链接

<div class="menu-toggle">
    <a href="#">
        <i class="fa fa-bars"></i>
        <span>Menu</span>
        </a>
</div>

And here is my js code这是我的js代码

$('.menu-toggle > a').on('click', function (e) {
        e.preventDefault();
        $('#responsive-nav').toggleClass('active');
    })

My CSS code is我的 CSS 代码是

.header-ctn .menu-toggle {
  display: none;
}
@media only screen and (max-width: 991px) {
  .header-ctn .menu-toggle {
    display: inline-block;
  }
  #responsive-nav {
    position: fixed;
    left: 0;
    top: 0;
    background: #15161D;
    height: 100vh;
    max-width: 250px;
    width: 0%;
    overflow: hidden;
    z-index: 22;
    padding-top: 60px;
    -webkit-transform: translateX(-100%);
    -ms-transform: translateX(-100%);
    transform: translateX(-100%);
    -webkit-transition: 0.2s all;
    transition: 0.2s all;
  }
  #responsive-nav.active {
    -webkit-transform: translateX(0%);
    -ms-transform: translateX(0%);
    transform: translateX(0%);
    width: 100%;
  }

I have included both my local js file and jquery file from CDN我已经包含了我的本地 js 文件和来自 CDN 的 jquery 文件

@GemeAlex @GemeAlex

Can you please check the browser version in prod env and your local env.您能否检查产品环境和本地环境中的浏览器版本。 because toggle is very simple thing and as you said if it is working in your local, then i doubt it can be a version mismatch or the browser in prod env is not supporting the toggle.因为切换是非常简单的事情,正如您所说,如果它在您的本地工作,那么我怀疑它可能是版本不匹配或 prod env 中的浏览器不支持切换。

You gave max-width: as 991px.你给了 max-width: 991px。 So when you resize the browser more than 991px, the "#responsive-nav {" will not work.因此,当您调整浏览器的大小超过 991 像素时,“#responsive-nav {”将不起作用。 change the max-width to 1440px.将最大宽度更改为 1440 像素。 It will work in desktop view as well它也可以在桌面视图中工作

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

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