我有用于滑入和滑出显示在手机中的菜单的代码。这些代码适用于新手机,但在旧手机中,当我打开网站菜单已经出来并且无法滑入时,它不会滑入。
代码
$(function() {
$("#trigger").click(function() {
$(".mainMenu").toggleClass("active");
});
$("#trigger").click(function() {
$("#trigger").toggleClass("active");
});
});

nav {
height: 40px;
width: 100%;
background: #1a001a;
font-size: 10pt;
font-family: 'PT Sans', Arial, sans-serif;
font-weight: bold;
position: relative;
border-bottom: 2px solid #734088;
}
nav ul {
padding: 0;
margin-top: 0;
margin: left;
width: 700px;
height: 40px;
}
nav li {
display: inline;
float: left;
}
.mainMenu:before,
.mainMenu:after {
content: " ";
display: table;
}
.mainMenu:after {
clear: both;
}
.mainMenu {
*zoom: 1;
}
.Login:before,
.Login:after {
content: " ";
display: table;
}
nav a {
color: #fff;
display: inline-block;
width: 80px;
text-align: center;
text-decoration: none;
line-height: 40px;
text-shadow: 1px 1px 0px #330010;
clear: both;
}
nav li a {
border-right: 1px solid #A28FA9;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover,
nav a:active {
background-color: #A28FA9;
}
.mainMenu li ul {
display: none;
position: absolute;
background-color: #1a001a;
height: auto;
}
.mainMenu li:hover ul {
display: block;
width: 150px;
}
.mainMenu li li {
list-style: none;
display: list-item;
}
.mainMenu li li a {
color: #fff;
display: inline-block;
width: 150px;
text-decoration: none;
line-height: 40px;
text-shadow: 1px 1px 0px #330010;
clear: both;
}
.mainMenu li li a:hover {
background-color: #A28FA9;
}
#trigger {
display: none;
}
.firstList {
float: left;
width: 85%;
}
@media only screen and (max-width: 480px) {
nav {
background: #0d0d0d;
position: absolute;
font-size: 10pt;
padding: 0;
width: 50%;
height: 100%;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
z-index: 10;
transform: translate(-150%, 0px);
transition: all 0.75s ease-in-out;
}
nav li {
height: 100%;
float: none;
position: relative;
width: 100%;
}
nav ul {
margin: 16px 0;
padding: 0;
display: block;
color: white;
list-style: none;
width: 100%;
height: 100%;
float: left;
}
.mainMenu {
clear: left;
}
.Login {
clear: both;
}
nav ul li {
margin: 0;
transition: all 0.25s ease-in-out;
}
nav ul li:hover {
color: #bdc3c7;
cursor: pointer;
}
nav li a {
border-top: none;
border-bottom: 2px solid #1a1a1a;
border-right: none;
}
nav a {
text-align: left;
width: 100%;
text-indent: 20px;
display: block;
background-color: #0d0d0d;
line-height: 35px;
}
nav.active {
-webkit-transform: translate(0%, 0px);
transform: translate(0%, 0px);
transition: all 0.75s ease-in-out;
}
#trigger {
background-color: #1a001a;
width: 100%;
height: 35px;
color: #FFF;
display: inline-block;
position: relative;
}
.firstList {
float: left;
width: 100%;
}
}

<nav class="mainMenu">
<div class="">
<div class="firstList">
<ul class="mainMenu">
<li><a href="#">link 1</a>
</li>
<li><a href="#">link 2</a>
</li>
<li><a href="#">link 3</a>
</li>
<li><a href="#">link 4</a>
<ul>
<li><a href="#">sublink 1</a>
</li>
<li><a href="#">sublink 2</a>
</li>
<li><a href="#">sublink 3</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
&#13;
答案 0 :(得分:1)
您正在使用css transform
属性来隐藏您的菜单,因此您没有使用-webkit-
或-ms-
等供应商前缀作为前缀。
尝试确定您要支持的浏览器版本,并相应地为您的css属性添加前缀。
以下概述了哪些版本需要转换功能的前缀:http://caniuse.com/#search=transform
答案 1 :(得分:0)
并非所有手机特别是旧款手机都支持javascript,你应该在页面加载时检测到javascript,如果没有检测到javascript,请在css中进行滑动。
或使用<nonscript>place the css for slide out here</noscript>
您可以参考此网站以查看支持哪些手机http://www.quirksmode.org/m/table.html