overscroll-behavior CSS property sets what a browser does when reaching the boundary of a scrolling area. It's a shorthand for overscroll-behavior-x and overscroll-behavior-y .

/* 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: unset;
					

By default, mobile browsers tend to provide a "bounce" effect or even a page refresh when the top or bottom of a page (or other scroll area) is reached. You may also have noticed that when you have a dialog box with scrolling content on top of a page of scrolling content, once the dialog box's scroll boundary is reached, the underlying page will then start to scroll — this is called scroll chaining .

In some cases these behaviors are not desirable. You can use overscroll-behavior to get rid of unwanted scroll chaining and the browser's Facebook/Twitter app-inspired "pull to refresh"-type behavior.

句法

overscroll-behavior property is specified as one or two keywords chosen from the list of values below.

Two keywords specifies the overscroll-behavior value on the x and y axes respectively. If only one value is specified, both x and y are assumed to have the same value.

auto

The default scroll overflow behavior occurs as normal.

contain

Default scroll overflow behavior is observed inside the element this value is set on (e.g. "bounce" effects or refreshes), but no scroll chaining occurs to neighbouring scrolling areas, e.g. underlying elements will not scroll.

none

No scroll chaining occurs to neighbouring scrolling areas, and default scroll overflow behavior is prevented.

形式定义

初始值 auto
适用于 non-replaced block-level elements and non-replaced inline-block elements
继承 no
计算值 如指定
动画类型 discrete

形式句法

[ contain | none | auto ]{1,2}
					

范例

Preventing an underlying element from scrolling

In our overscroll-behavior example (see the source code also), we present a full-page list of fake contacts, and a dialog box containing a chat window.

Both of these areas scroll; normally if you scrolled the chat window until you hit a scroll boundary, the underlying contacts window would start to scroll too, which is not desirable. This can be stopped using overscroll-behavior-y ( overscroll-behavior would also work) on the chat window, like this:

.messages {
  height: 220px;
  overflow: auto;
  overscroll-behavior-y: contain;
}
					

We also wanted to get rid of the standard overscroll effects when the contacts are scrolled to the top or bottom (e.g. Chrome on Android refreshes the page when you scroll past the top boundary). This can be prevented by setting overscroll-behavior: none on the <body> 元素:

body {
  margin: 0;
  overscroll-behavior: none;
}
					

规范

规范 状态 注释
CSS Overscroll Behavior Module Level 1
The definition of 'overscroll-behavior' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
overscroll-behavior Chrome 完整支持 63 Edge 部分支持 18 注意事项
部分支持 18 注意事项
注意事项 Currently the none value incorrectly behaves as contain (allowing for the elastic bounce effect).
Firefox 完整支持 59 IE 不支持 No Opera 完整支持 50 Safari 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 176454 .
WebView Android 完整支持 63 Chrome Android 完整支持 63 Firefox Android 完整支持 59 Opera Android 完整支持 46 Safari iOS 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 176454 .
Samsung Internet Android 完整支持 8.0

图例

完整支持

完整支持

部分支持

部分支持

不支持

不支持

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: