gpt4 book ai didi

jquery - 当固定位置 div 处于事件状态时禁用 iPad、iPhone 上的滚动

转载 作者:太空宇宙 更新时间:2023-11-04 02:22:58 25 4
gpt4 key购买 nike

所以目前我正在做一些 iPhone 和 iPad 测试,并注意到一个与滚动相关的非常烦人的错误。所以目前我的基本页面是这样的:

<body>
<div>
Content of my website...
<button>This button uses jQuery to add a class to the fixed-form div</button>
</div>
<div class="fixed-form">
<form>
</form>
</div>
</body>

这是一个非常基本的 HTML 示例,在正文中显示了我的基本内容区域,但是我还有一个名为 fixed-form 的 div,当在内容区域中按下按钮时,它会添加一个fixed-form div 具有以下样式的类:

  z-index:0;
color:#fff;
position: fixed;
height: 100% !important;
overflow-y:auto;
-webkit-overflow-scrolling: touch;
overflow-x:hidden;
top:0;
width:100%;
z-index:999 !important;

fixed-form div 然后覆盖视口(viewport)。问题是 fixed-form 后面的内容/正文仍然可以滚动,元素仍然可以点击。 z-index 肯定会阻止这种情况发生,但事实并非如此。知道为什么会这样吗?我只想完全禁用所有不是 fixed-form div 的内容,使其无法滚动和点击。

更新:到目前为止,我已尝试将 overflow:hidden 添加到内容 div 中,但这确实会停止水平滚动,但不会影响垂直滚动问题。

谢谢

最佳答案

您应该在 body 而不是 div 元素上添加 class。并在 div 处于事件状态时在 body 上添加以下 css。

body.form-active {
overflow: hidden;
height: 100%;
}

$('button').click(function() {
$('body').toggleClass('form-active');
});
body.form-active {
height: 100%;
overflow: hidden;
}
.fixed-form {
background: #000;
z-index:0;
color:#fff;
position: fixed;
height: 100% !important;
overflow-y:auto;
-webkit-overflow-scrolling: touch;
overflow-x:hidden;
top:0;
width:100%;
z-index:999 !important;
display: none;
}
.form-active .fixed-form {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>
<div>
Content of my website... Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...Content of my website...
<button>This button uses jQuery to add a class to the body</button>
</div>
<div class="fixed-form">
Form content Goes here...
<button>This button uses jQuery to add a class to the body</button>
<form>
</form>
</div>
</body>

关于jquery - 当固定位置 div 处于事件状态时禁用 iPad、iPhone 上的滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37810011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com