打开移动菜单时如何禁用后台滚动? [英] How to disable scrolling in the background when the mobile menu is open?
本文介绍了打开移动菜单时如何禁用后台滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在建立一个具有导航菜单的移动响应网站. 当我到达菜单底部时-如果在到达菜单底部时继续滚动-它将在后台滚动页面. 如何禁用它?
I am building a mobile responsive website that has a nav menu. When I get to the bottom of the menu - If I continue scrolling when I reach the bottom of the menu - it scrolls the page in the background. How can I disable it?
到目前为止,这是我的jQuery代码:
This is my jQuery code so far:
// When the document is loaded...
$(document).ready(function() {
$('#mob-menu-btn').click(function(){
$('.sports').slideToggle("slow");
})
$('#sub-menu').click(function(){
$('.sports2').slideToggle("slow");
})
});
这是我的CSS:
.list{
width: 100%;
overflow: hidden;
overflow-y: auto;
top: -10%;
overflow: hidden;
overflow-y: auto;
}
.sports li{
list-style-image:none;
list-style-type: none;
border-bottom: 2px solid #eeeeee;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 10px;
width:100%;
font-family: arial;
text-decoration: none;
overflow: hidden;
}
推荐答案
打开菜单时,将位置设置为固定在主体上.当您关闭它时,请删除该属性.最好使用添加/删除类.
When menu is open, set position fixed to the body. When you close it, remove that property. Better use add/remove class.
if($('#mob-menu').is(':visible'))
{
$('body').addClass("fixedPosition");
}
else
{
$('body').removeClass("fixedPosition");
}
.fixedPosition
{
position: fixed;
}
这篇关于打开移动菜单时如何禁用后台滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文