
# Prevent scrolls from escaping a fixed position element # The chatbox scenario Content beneath the chat window scrolls too :(Ĭonsider a fixed positioned chatbox that sits at the bottom of the page.
#Scroll on overflow css how to#
Let's dive into some examples to see how to use overscroll-behavior. Overscroll-behavior also supports shorthands for overscroll-behavior-x and overscroll-behavior-y if you only want to define behaviors for a certain axis.
#Scroll on overflow css android#
Android overscroll glow or iOS rubberbanding).


none - same as contain but it also prevents overscroll effects within the node itself (e.g.Note: using overscroll-behavior: contain on the html element prevents overscroll navigation actions. For example, the overscroll glow effect on Android or the rubberbanding effect on iOS which notifies the user when they've hit a scroll boundary. Scrolls do not propagate to ancestors but local effects within the node are shown. Scrolls that originate on the element may propagate to ancestor elements. The property takes three possible values: The best part is that using overscroll-behavior does not adversely affect page performance like the hacks mentioned in the intro! You can use it to cancel scroll chaining, disable/customize the pull-to-refresh action, disable rubberbanding effects on iOS (when Safari implements overscroll-behavior), and more. The overscroll-behavior property is a new CSS feature that controls the behavior of what happens when you over-scroll a container (including the page itself). We can do better! # Introducing overscroll-behavior These workarounds have well-documented negative effects on scrolling performance. Developers end up writing unnecessary JavaScript, add non-passive touch listeners (which block scrolling), or stick the entire page in a 100vw/vh (to prevent the page from overflowing). The unfortunate part is that this type of customization has been tricky to pull off. There's also the potential to see a double refresh animation! Alternatively, it might be nicer to customize the browser's action, aligning it more closely to the site's branding. Why? In this app, you probably don't want the user accidentally refreshing the page. Swiping down at the top of the page refreshes the entire page:Ĭhrome Android's native pull-to-refresh actionįor situations like the Twitter PWA, it might make sense to disable the native pull-to-refresh action.

In fact, this particular UX has become so popular that mobile browsers like Chrome on Android have adopted the same effect. Pulling down on a social feed and releasing creates new space for more recent posts to be loaded. Pull-to-refresh is an intuitive gesture popularized by mobile apps such as Facebook and Twitter. Certain apps may want to provide a different user experience when the user hits a scroll boundary. Oftentimes the default is pretty nice, but sometimes it's not desirable or even unexpected. Turns out this behavior is called scroll chaining the browser's default behavior when scrolling content. The content behind the drawer starts scrolling! Scrolling is taken over by the parent container the main page itself in the example. But notice what happens if the user continues to scroll. In other words, the user reaches a "scroll boundary". When they reach the bottom, the overflow container stops scrolling because there's no more content to consume. As an example, take an app drawer with a large number of items that the user may have to scroll through. Scrolling is one of the most fundamental ways to interact with a page, but certain UX patterns can be tricky to deal with because of the browser's quirky default behaviors. # Background # Scroll boundaries and scroll chaining Scroll chaining on Chrome Android. It's in development or being considered by other browsers. This is different to the first version of the spec, which allowed you to set snap-points manually using the repeat keyword. In its most basic form, it looks like this: When the container element is scrolled, it will snap to the child elements you’ve defined.

Scroll snapping is used by setting the scroll-snap-type property on a container element and the scroll-snap-align property on elements inside it.
