overscroll-behavior

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上執行。自 2022 年 9 月起,所有瀏覽器都已支援此功能。

overscroll-behavior CSS 屬性設定瀏覽器在滾動區域邊界處執行的操作。

試一試

overscroll-behavior: auto;
overscroll-behavior: contain;
overscroll-behavior: none;
<section class="default-example" id="default-example">
  <div class="example-container">
    <div class="box">
      This is a scrollable container. Michaelmas term lately over, and the Lord
      Chancellor sitting in Lincoln's Inn Hall. Implacable November weather. As
      much mud in the streets as if the waters had but newly retired from the
      face of the earth.
      <br /><br />
      Lorem Ipsum has been the industry's standard dummy text ever since the
      1500s, when an unknown printer took a galley of type and scrambled it to
      make a type specimen book. It has survived not only five centuries, but
      also the leap into electronic typesetting, remaining essentially
      unchanged.
    </div>
    <div id="example-element">
      This is the inner container. Focus on this container, scroll to the bottom
      and when you reach the bottom keep scrolling.
      <p>
        If you have
        <code class="language-css">overscroll-behavior: auto;</code> selected
        the outer container will start to scroll.
      </p>
      If you have
      <code class="language-css">overscroll-behavior: contain;</code> selected,
      the outer container will not scroll unless you move your cursor out of the
      inner container and try to perform scroll on the outer container.
    </div>
  </div>
</section>
.example-container {
  width: 35em;
  height: 18em;
  border: medium dotted;
  padding: 0.75em;
  text-align: left;
  overflow: auto;
  display: flex;
}

.box {
  width: 50%;
}

#example-element {
  width: 50%;
  height: 12em;
  border: medium dotted #1b76c4;
  padding: 0.3em;
  margin: 0 0.3em;
  text-align: left;
  overflow: auto;
  overscroll-behavior: contain;
}

構成屬性

此屬性是以下 CSS 屬性的簡寫:

語法

css
/* Keyword values */
overscroll-behavior: auto; /* default */
overscroll-behavior: contain;
overscroll-behavior: none;

/* Two values */
overscroll-behavior: auto contain;

/* Global values */
overscroll-behavior: inherit;
overscroll-behavior: initial;
overscroll-behavior: revert;
overscroll-behavior: revert-layer;
overscroll-behavior: unset;

overscroll-behavior 屬性被指定為一個或兩個關鍵字,從下面的值列表中選擇。

兩個關鍵字分別指定 xy 軸上的 overscroll-behavior 值。如果只指定一個值,則 x 和 y 被假定為具有相同的值。

auto

預設的滾動溢位行為正常發生。

contain

預設的滾動溢位行為(例如,“彈跳”效果)在設定此值的元素內部可見。但是,鄰近的滾動區域不會發生滾動連結;下層元素不會滾動。contain 值會停用原生瀏覽器導航,包括垂直的下拉重新整理手勢和水平的滑動導航。

none

鄰近的滾動區域不會發生滾動連結,並且會阻止預設的滾動溢位行為。

描述

預設情況下,移動瀏覽器在頁面(或其他滾動區域)的頂部或底部達到時,往往會提供“彈跳”效果,甚至頁面重新整理。你可能還注意到,當你有一個帶有可滾動內容的對話方塊位於一個也帶有可滾動內容的頁面頂部時,一旦對話方塊的滾動邊界達到,下層頁面就會開始滾動——這被稱為滾動連結

在某些情況下,這些行為是不希望的。你可以使用 overscroll-behavior 來擺脫不需要的滾動連結和瀏覽器受 Facebook/Twitter 應用啟發的“下拉重新整理”型別的行為。

請注意,此屬性僅適用於滾動容器。特別是,由於