【发布时间】:2017-07-07 02:55:26
【问题描述】:
我正在开发我的响应式菜单,该菜单将在桌面上查看正常的水平菜单,但是当屏幕小于 992 像素时,会出现一个汉堡样式按钮,该按钮将切换一个推入式侧边菜单。
我面临的问题是在调整窗口大小时菜单出现故障,也就是在桌面和移动视图之间切换。
这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menu</title>
<meta charset="utf-8">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
我的CSS:
@media screen and (min-width: 992px) {
}
还有我的 js:
$(document).ready(function(){
$('#mobile-icon').click(function(){
$(this).toggleClass('closed');
});
$('.expander-icon').click(function(){
$(this).parent().toggleClass('active-menu');
});
});
$(window).on('load resize', function () {
var screenWidth = $( window ).width();
if(screenWidth < 992){
$('.u').addClass('isMobile');
$('#icon').click(function(){
$(this).toggleClass("open closed");
if($( "#con" ).hasClass( "open" )){
$('.gation').css('margin-left',"0");
}
else{
$('.asdn').css('margin-left',"-70%");
}
});
}
});
【问题讨论】:
-
菜单“故障”是什么意思?
-
“桌面”菜单在我从移动分辨率调整大小后不会显示,反之亦然,或者移动菜单按钮在点击时不会执行任何操作,它会自动出错
标签: javascript jquery html css