1

我有一个很奇怪的问题。也许scroll-snaps行为中的错误?

当我到达页面顶部并继续向上滚动时,如果我不再向下滚动,身体就会溢出并停留在那里。即使我重新加载页面。

仅在 Mac 版 Chrome(版本 75.0.3770.100(官方构建)(64 位))中发生,我已经在 Safari 和 Firefox 中对其进行了测试,并且两者似乎都表现正常。

在线复制

Jsfiddle在这里,但你不能在那里复制它。可能是因为它在 iframe 内?

问题视频:

在此处输入图像描述

4

4 回答 4

4

好吧,在修复了您对快照滚动的使用之后,我寻找了类似的问题和解决方案,可以添加以下内容:

html{
    height: 100%;
    overflow: hidden;
}
body{
    height: 100%;
    overflow: auto;
}

在某些情况下,这显然是不够的,因此您还可以添加:

body{
    overscroll-behavior: none;
}
于 2019-07-01T20:39:10.043 回答
2

您需要添加过度滚动行为。这控制您是否可以滚动到网站内容的下方或上方。通常用于具有“拉动刷新”的网站。在此处阅读更多信息:https ://developers.google.com/web/updates/2017/11/overscroll-behavior 。

scroll-snap-type: y mandatory;    
overscroll-behavior-y: none;
于 2019-09-09T16:03:11.370 回答
0

只需添加两行 css 即可解决您的问题。将高度设为100%to100vh并给出box-sizing:border-box;这将修复您的填充属性100%宽度和高度;框尺寸:边框框;. 为什么我使用vh整个视口高度的百分比。10vh 将解析为当前视口高度的 10%,这将为您提供更多responsive内容。但是如果你想使用100%它也可以正常工作box-sizing:border-box;

 html,body,#container, .section, .slide{
        height: 100vh;
        box-sizing:border-box;
 }

这是您的解决方案代码

html,body,#container, .section, .slide{
            height: 100%;
            box-sizing:border-box;
     }
于 2019-07-02T06:02:20.557 回答
0

也许,您应该尝试替换:

body{
  -ms-scroll-snap-type: y mandatory;
  scroll-snap-type: y mandatory;
}

通过这个:

#container {
  -ms-scroll-snap-type: y mandatory;
  scroll-snap-type: y mandatory;
  overflow-y: scroll;
}

我在这里给你留下了另一个例子:

body {
  height: 100vh;
  margin: 0;  
}

.container {
  -ms-scroll-snap-type: y mandatory;
  scroll-snap-type: y mandatory;
  overflow-y: scroll;
  height: 100%;
}

.container div {
  scroll-snap-align: start;

  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 4rem;
}

.container div:nth-child(1) {
  background: yellow;
  color: black;
}

.container div:nth-child(2) {
  background: red;
  color: white;
}

.container div:nth-child(3) {
  background: blue;
  color: white;
}

.container div:nth-child(4) {
  background: green;
  color: white;
}
<div class="container">
  <div>Section 1</div>
  <div>Section 2</div>
  <div>Section 3</div>
  <div>Section 4</div>
</div>

于 2019-07-01T22:27:52.267 回答