css - 如何防止 CSS 3D 转换的元素扩展页面?
问题描述
在我的 CSS 视差中,我将<body>
and设置<html>
如下:
@supports (perspective: 1px) { /* The parallax atmosphere */
html {
height: 100%;
overflow: hidden;
overscroll-behavior: none;
scroll-behavior: smooth;
}
html > body {
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow-x: hidden;
overflow-y: auto;
overscroll-behavior: none;
perspective: 1px;
transform-style: preserve-3d;
transform: translateZ(0);
scroll-behavior: smooth;
}
html > body:after {
content: "";
display: block;
clear: both;
}
}
这是其中一个视差层的 CSS 示例(重要部分):
#aF-background-layer-1 {
position: absolute;
z-index: -1;
overflow: hidden; /* Because it wraps an SVG */
}
@supports (perspective: 1px) {
#aF-background-layer-1 {
-webkit-transform: translateZ(-72px) scale(73);
transform: translateZ(-72px) scale(73);
will-change: transform;
}
}
还有更多的 CSS,但这只是为了给图层提供它们的尺寸、颜色、如何处理里面的 SVG,这一切都很漂亮。问题是当您滚动到页面底部时。在 Chrome 中,当您到达<body>
. 在 FireFox 和 Safari(不确定 IE/Edge 或其他)中,滚动不会停止,直到您到达所有元素的底部。如果任何元素距离很远(在滚动时移动非常缓慢),这可以持续相当长的距离。所以问题是:
如何在结尾处停止滚动<body>
?
我不能只在页面上使用overflow: hidden;
,<body>
因为页面甚至不会滚动。我更喜欢用 CSS 来做这件事,而不是 JS。这是一个可以玩的沙盒:
解决方案
在您的 html 头中将高度指定为 200vh:
<head>
<meta name="viewport" content="width=device-width" height="200vh" user-scalable="yes" initial-scale="1.0">
</head>
更改 CSS 中 html 和 body 的高度:
html {
height: 200vh;
}
html > body {
height: 200vh;
}
我不确定这些是你想要的数字,但你需要它们匹配。
推荐阅读
- continuous-integration - 为什么外部 git 存储库不是 Azure 门户中部署中心的选项?
- swift - Swift 泛型:使用泛型类型的属性扩展非泛型类型,其中泛型参数是扩展类型
- jekyll - 更改博客文章的 Jekyll URL
- matlab - 如何删除极坐标图上的 theta 网格和半径网格?
- html - 3个下拉单独的下拉列表,只选择最上面的一个
- asp.net - 如果没有结果,Gridview 就会消失
- javascript - 使用按字母顺序排序的选项填充选择
- javascript - 如何将 JSON 数据分解为子字符串,以便以后计算?
- android - 是否可以允许刷卡(刷卡)但禁止在 Android 中输入?
- django - 为什么 wagtail 无法识别我的模板?