你好,这是我的第一篇文章。
我在这里搜索了很多,但我不知道如何在添加固定到正文的位置后阻止我的页面转到顶部。
我想要的和这个类似,但是我不能让它工作Prevent page scrolling to top upon adding fixed position
让我把话说清楚。当我的移动菜单打开时,我想要使正文不可滚动(固定),但添加位置固定会使我的页面转到顶部。
CSS
.site-navigation { position: fixed; width: 100%; }
@media screen and (max-width: 991px) {
.is-menu-toggled-on .nav-menu {
height: 400px;
overflow-y: scroll;
overflow-x:hidden;}
.is-menu-toggled-on body
{
position: fixed;
overflow: hidden;
width: 100%
}
看这儿。每次我按下汉堡包菜单图标(3行),菜单栏打开时,下面的页面会滚动回到顶部...A我想让它在当前位置不可滚动--> https://imgshare.io/image/SQzVZ
我知道这可以与一些javascript一起工作,我已经尝试了网站上的许多javascript,但我做不到。如果你能帮助我,我将不胜感激。
发布于 2019-06-28 08:10:40
只需在position: fixed;
上添加overflow: hidden;
以防止滚动,而不是html。最终touch-action: none; pointer-events: none;
也是如此。
html {
overflow-x: hidden;
overflow-y: auto;
}
html.is-menu-toggled-on {
overflow: hidden;
pointer-events: none;
touch-events: none;
}
body {
overflow: visible;
pointer-events: all;
touch-events: auto;
}
https://stackoverflow.com/questions/56799497
复制相似问题