简体   繁体   English

如何在移动设备上滚动叠加div

[英]How to scroll an overlay div on mobile

I've got a mobile website that has a navigation menu that is displayed on click of a fixed position button in the top right. 我有一个移动网站,其中有一个导航菜单,点击右上角的固定位置按钮即可显示。 This menu is also fixed so that the top of the menu starts 10px below the bottom of the button. 此菜单也是固定的,因此菜单顶部的开头位于按钮底部下方10px处。 The problem is that this navigation menu can be longer than the height of the device being used, and when you try and scroll it will scroll the content behind the navigation menu seeing as it is fixed. 问题是此导航菜单可能比正在使用的设备的高度更长,当您尝试滚动时,它将滚动导航菜单后面的内容,看它是否已修复。 Can someone help me get around this? 有人可以帮我解决这个问题吗?

As per my comment: 根据我的评论:

You need to use JS to find the height of the screen, top of the menu and set the max height of the menu to the difference of these 您需要使用JS来查找屏幕的高度,菜单顶部并将菜单的最大高度设置为这些的差异

For the height of the window use $('window').height() 对于窗口的高度,使用$('window').height()

For the menu's distance from the top of the browser: $('.menu').offset() 对于菜单距离浏览器顶部的距离: $('.menu').offset()

The function should live in the show menu event listener: 该函数应该存在于show menu事件监听器中:

var maxHeight = $(window).height() - $('.menu').offset();
$('.menu').css({ "max-height" :maxHeight})

Make sure that overflow:scroll; 确保overflow:scroll; is set on your menu menu上设置

What you need to do is put a div with a class (I chose scrollable ) inside the navigation menu that has the scrollable content and then set the css for that div to be something along the lines of : 你需要做的是在导航菜单中放置一个带有类(我选择scrollable )的div,它具有可滚动内容,然后将该div的css设置为以下内容:

div.scrollable{
   overflow : auto;
   position : relative;
   }

That way, the div (and the inside content of the navigation menu) will be scrollable while the position overall of the menu remains fixed. 这样,div(以及导航菜单的内部内容)将是可滚动的,而菜单的整体位置保持固定。

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

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