--- title: overscroll-behavior slug: Web/CSS/overscroll-behavior tags: - CSS translation_of: Web/CSS/overscroll-behavior ---
The overscroll-behavior
CSS property is shorthand for the {{cssxref("overscroll-behavior-x")}} and {{cssxref("overscroll-behavior-y")}} properties, which allow you to control the browser's scroll overflow behavior — what happens when the boundary of a scrolling area is reached.
/* Значения-ключевые слова */ overscroll-behavior: auto; /* по умолчанию */ overscroll-behavior: contain; overscroll-behavior: none; /* Двойное значение */ overscroll-behavior: auto contain; /* Глобальные значения */ overflow: inherit; overflow: initial; overflow: unset;
По умолчанию, мобильные браузеры как правило обеспечивают эффект "отскока" или даже обновляют страницу при достижение ее верхней или нижней части (или другой области прокрутки). 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.
{{cssinfo}}
The 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
contain
none
{{csssyntax}}
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 {{htmlelement("body")}} element:
body { margin: 0; overscroll-behavior: none; }
Until the CSSWG publishes their own draft, the specification can only be found in its WICG Github Repository.
Specification | Status | Comment |
---|---|---|
{{SpecName('Overscroll Behavior', '#propdef-overscroll-behavior', 'overscroll-behavior')}} | {{Spec2('Overscroll Behavior')}} |
{{Compat("css.properties.overscroll-behavior")}}