試一試
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 屬性的簡寫:
語法
/* 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 屬性被指定為一個或兩個關鍵字,從下面的值列表中選擇。
兩個關鍵字分別指定 x 和 y 軸上的 overscroll-behavior 值。如果只指定一個值,則 x 和 y 被假定為具有相同的值。
值
描述
預設情況下,移動瀏覽器在頁面(或其他滾動區域)的頂部或底部達到時,往往會提供“彈跳”效果,甚至頁面重新整理。你可能還注意到,當你有一個帶有可滾動內容的對話方塊位於一個也帶有可滾動內容的頁面頂部時,一旦對話方塊的滾動邊界達到,下層頁面就會開始滾動——這被稱為滾動連結。
在某些情況下,這些行為是不希望的。你可以使用 overscroll-behavior 來擺脫不需要的滾動連結和瀏覽器受 Facebook/Twitter 應用啟發的“下拉重新整理”型別的行為。
請注意,此屬性僅適用於滾動容器。特別是,由於 不是滾動容器,在此 iframe 上設定此屬性無效。要控制來自 iframe 的滾動連結,請在 iframe 文件的 和 元素上設定 overscroll-behavior。
正式定義
正式語法
overscroll-behavior =
[ contain | none | auto ]{1,2}
示例
防止下層元素滾動
在我們的 overscroll-behavior 示例(也請參閱原始碼)中,我們展示了一個全頁的虛假聯絡人列表和一個包含聊天視窗的對話方塊。

這兩個區域都可滾動;通常,如果你滾動聊天視窗直到達到滾動邊界,下層的聯絡人視窗也會開始滾動,這是不希望的。這可以透過在聊天視窗上使用 overscroll-behavior-y(overscroll-behavior 也可以)來阻止,如下所示
.messages {
height: 220px;
overflow: auto;
overscroll-behavior-y: contain;
}
我們還希望消除聯絡人滾動到頂部或底部時的標準過度滾動效果(例如,Android 上的 Chrome 在滾動超出頂部邊界時會重新整理頁面)。這可以透過在元素上設定 overscroll-behavior: none 來阻止。
html {
margin: 0;
overscroll-behavior: none;
}
規範
| 規範 |
|---|
| CSS Overscroll Behavior Module Level 1 # overscroll-behavior 屬性 |
瀏覽器相容性
載入中…
另見
- CSS overscroll behavior 模組
- CSS 滾動錨定模組
- 掌控你的滾動:自定義下拉重新整理和溢位效果,在 developer.chrome.com 上 (2017)