I currently have a slide-out menu on my webpage, which is 350px wide
let menuGeneral = $('#menu-general');
$('#menu-up-control').click(function () {
menuGeneral.animate({ right: '0' }, 500);
});
$('#menu-up-control-close').click(function () {
menuGeneral.animate({ right: '-350px' }, 500, function () {
menuGeneral.hide();
});
});
.menu-up-control {
float:right;
font-size:26px;
top:3px;
position:relative;
cursor:pointer;
padding:10px 100px 0 0;
}
.menu-up-control-close {
width:15px;
}
.menu-up-control-close i {
color:white;
font-size:40px;
top:3px;
position:relative;
cursor:pointer;
padding:10px 0px;
margin:50px 0 0 40px;
}
.menu-general {
position:fixed;
width:350px;
top:0;
right:-350px;
bottom:0;
z-index:9999;
padding:10px;
background-color:black;
}
.menu-main li, .menu-main li a {
font-size:36px;
font-weight:700;
}
.menu-main li a {
font-weight:bold;
color:white;
text-decoration:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css"
rel="stylesheet" type='text/css'>
<a id="menu-up-control" class="menu-up-control">
<i class="fa fa-bars"></i>
</a>
<div id="menu-general" class="menu-general"gt;
<div id="menu-up-control-close" class="menu-up-control-close">
<i class="fa fa-times"></i>
</div>
<ul class="menu-main">
<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></li>
</ul>
</div>
However, I want to modify it so that for mobile devices with a screen width of 767px or greater, the menu stretches across the entire width of the screen
I have added width: 100%
to the css class .menu-general
In the JavaScript code, I have added the following
let menuGeneral = $('#menu-general');
if ($(document).width() > 767) {
menuGeneral.animate({ right: '0' }, 500);
} else {
menuGeneral.animate({ right: '0' }, 500);
}
if ($(document).width() > 767) {
menuGeneral.animate({ right: '-350px' }, 500);
} else {
menuGeneral.animate({ right: $(window).width() }, 500);
}
For desktop displays, the .menu-general
class includes right:-350px;
, but I am unsure how to adjust this for mobile devices so that the menu hides appropriately based on screen size