【问题标题】:IE (!) Fixed element scrolls on scroll (scroll-wheel and keyboard)IE(!)固定元素滚动滚动(滚轮和键盘)
【发布时间】:2020-07-22 05:43:19
【问题描述】:

在 IE11 中测试这段代码!它是复杂页面的精简版,适用于除 IE11 以外的所有浏览器。我需要支持这个浏览器。

.theme-layout {
  display: -webkit-box;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
          flex-direction: column;
  height: 100vh;
  max-height: 100vh;
}

.theme-content {
  -webkit-box-ordinal-group: 2;
          order: 1;
  width: 100%;
  -webkit-box-flex: 1;
          flex-grow: 1;
  display: -webkit-box;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
          flex-direction: row;
  flex-wrap: nowrap;
  -webkit-box-align: stretch;
          align-items: stretch;
  position: relative;
}

.theme-main {
  flex-basis: 100%;
  -webkit-box-ordinal-group: 3;
          order: 2;
}

.composite-page {
  padding-bottom: 7.5rem;
}

.composite-page-background {
  margin: 0;
}
.composite-page-background picture {
  position: fixed;
  z-index: -1;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: -webkit-box;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
          flex-direction: row;
  flex-wrap: nowrap;
  -webkit-box-align: stretch;
          align-items: stretch;
}
.composite-page-background picture img {
  -o-object-fit: cover;
     object-fit: cover;
  -o-object-position: 50% 50%;
     object-position: 50% 50%;
  width: 100%;
}
.composite-page-background picture:after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(-10%, #0c6158), color-stop(60%, transparent));
  background-image: linear-gradient(to bottom, #0c6158 -10%, transparent 60%);
}

.theme-paragraph-section {
  height: calc(100vh - 7.5rem);
  display: -webkit-box;
  display: flex;
  scroll-snap-align: start;
}
@media screen and (max-width: 768px) {
  .theme-paragraph-section {
    height: auto;
  }
}
.theme-paragraph-section:target {
  -webkit-animation: theme-paragraph-section-blink 1.3s;
          animation: theme-paragraph-section-blink 1.3s;
}
@media (prefers-reduced-motion: reduce) {
  .theme-paragraph-section:target {
    -webkit-animation: none;
            animation: none;
  }
}
.theme-paragraph-section:before, .theme-paragraph-section:after {
  content: "";
  -webkit-box-flex: 1;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: calc(45rem / 2);
  pointer-events: none;
}
<div class="theme-layout">
  <div class="theme-content">
    <main class="theme-main" id="main-content" role="main">
      <div>
        <div id="block-mainpagecontent">
          <article class="composite-page">
            <figure class="composite-page-background">
              <picture>
                <source media="(min-width: 1601px)" srcset="https://picsum.photos/id/1/1920/1080">
                <source media="(min-width: 1381px)" srcset="https://picsum.photos/id/1/1600/900">
                <source media="(min-width: 1181px)" srcset="https://picsum.photos/id/1/1380/777">
                <source media="(min-width: 901px)" srcset="https://picsum.photos/id/1/1180/664">
                <source media="(min-width: 611px)" srcset="https://picsum.photos/id/1/900/507">
                <source media="(max-width: 610px)" srcset="https://picsum.photos/id/1/610/1084">
                <img src="https://picsum.photos/id/1/900/507">

              </picture>
            </figure>
            <div class="theme-paragraph-section" id="paragraph-45">
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
              Dummy Content<br><br><br>
            </div>
          </article>
        </div>
      </div>
    </main>
  </div>
</div>

由于 stackoverflow 不再支持 IE11,我链接到一个 codepen 调试视图,您可以在 IE11 中打开它:https://cdpn.io/HerrSerker/debug/748ff2e947bdc668a7af47e6eeb0872a

此代码包含一个响应式图像,该图像应覆盖整个窗口并在滚动时保持固定。 在此图像之前分层的是一些虚拟内容,这些内容会强制页面可滚动。

现在的问题:当我在 Internet Explorer 11 中滚动时,背景中的固定图像不固定,而是上下跳跃,但只有当我使用鼠标滚轮或键盘滚动时( SPACEUPDNPGUPPGDN)。如果我拖动滚动条,固定元素会保持应有的固定状态。

我用截屏视频制作了一个 GIF 来演示这个问题

【问题讨论】:

    标签: css internet-explorer scroll css-position fixed


    【解决方案1】:

    我尝试在 IE 11 浏览器中测试您的示例代码,我可以在那里看到问题。

    我尝试检查 CSS 代码,发现 .theme-content CSS 类中的 position: relative; 导致了这个问题。

    如果您删除或评论 position: relative; 则问题可以解决。

    在 IE 11 浏览器中的输出:

    【讨论】:

    • 感谢您的调查。这解决了给定的问题,但不幸的是它没有在我拥有的真实页面中解决它(无法链接到它!)。所以我必须扩展我的例子,直到问题没有再次解决。
    • 您可以尝试更新原始帖子中的示例,并在更新后发表评论。我们将再次尝试检查问题并尝试为您提供建议。感谢您的理解。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 2019-01-13
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多