我有一个很长的页面,我想隐藏在“折叠”下面的内容,并且它应该在iPhone/iPad上起作用。
应用于的overflow:hidden在移动Safari上似乎不起作用。 我不能在整个网站上创建一个包装器来实现这个...
你知道解决办法吗?
应用于的overflow:hidden在移动Safari上似乎不起作用。 我不能在整个网站上创建一个包装器来实现这个...
你知道解决办法吗?
我遇到了类似的问题,后来发现将overflow: hidden;
应用于html
和body
两者可以解决我的问题。
html,
body {
overflow: hidden;
}
对于iOS 9,您可能需要使用这个替代方法:(感谢chaenu!)
html,
body {
overflow: hidden;
position: relative;
height: 100%;
}
-webkit-
非常出色,领先于其他浏览器,每个人都想成为-webkit-
。现在到了2022年,苹果公司在支持Web方面犯了如此严重的错误,以至于今年没有一个月我没有遇到另一个问题,所有其他浏览器都能正常工作,而Safari却出现了问题。凭借苹果公司拥有的财务资源,他们应该对其Web产品的糟糕状态感到无比羞耻。 - Rouninbody {
position:relative; // that's it
overflow:hidden;
}
body
上使用这些规则吗? - vaskortbody
元素上切换这些规则的类时,似乎已经解决了。 - vaskortel.style.touchAction =“none”
(然后返回“”
)可以起作用。 - nishanthshanmugham这里列出的一些解决方案在拉伸弹性滚动时可能会出现一些奇怪的故障。为了修复这个问题,我使用了:
CSS
transform
translateZ(0)
body.lock-position {
height: 100%;
overflow: hidden;
width: 100%;
position: fixed;
}
来源: http://www.teamtownend.com/2013/07/ios-prevent-scrolling-on-body/
html,
body {
position: relative;
height: 100%;
overflow: hidden;
}
它可以在Safari浏览器中正常工作。
html,
body {
overflow: hidden;
position: fixed
}
height: 100%;
overflow: hidden;
width: 100%;
position: fixed;
还不够,它在iOS上的Safari中也无效。我还需要添加:
top: 0;
left: 0;
right: 0;
bottom: 0;
结合这里的答案和评论以及这个相似的问题,对我很有帮助。
因此,我整理出完整的答案如下。
以下是如何在站点内容周围添加一个包装器div,就在<body>
标签内部。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- other meta and head stuff here -->
<head>
<body>
<div class="wrapper">
<!-- Your site content here -->
</div>
</body>
</html>
.wrapper{
position:relative; //that's it
overflow:hidden;
}
我曾经使用过 <body>
和 <div class="wrapper">
当弹出窗口打开时...
<body>
的高度变为100%,并设置overflow:hidden
<div class="wrapper">
设置为position:relative;overflow:hidden;height:100%;
我使用JS/jQuery获取页面的实际滚动位置,并将该值存储为data-attribute以供body使用
然后我在.wrapper DIV中滚动到滚动位置(而不是在窗口中)
以下是我的解决方案:
JS/jQuery:
// when popup opens
$('body').attr( 'data-pos', $(window).scrollTop()); // get actual scrollpos
$('body').addClass('locked'); // add class to body
$('.wrapper').scrollTop( $('body').attr( 'data-pos' ) ); // let wrapper scroll to scrollpos
// when popup close
$("body").removeClass('locked');
$( window ).scrollTop( $('body').attr( 'data-pos' ));
CSS:
body.locked {position:relative;overflow:hidden;height:100%;}
body.locked .wrapper {position:relative;overflow:hidden;height:100%;}
它在桌面和移动端(iOS)上都运行良好。
欢迎提出提示和改进意见 :)
干杯!
html {
position:relative;
top:0px;
left:0px;
overflow:auto;
height:auto
}
.class-on-html{
position:fixed;
top:0px;
left:0px;
overflow:hidden;
height:100%;
}
toggleClass这个类用于切换页面
当你关闭这个类时,第一行将会调用滚动条返回