Back to Tailwindcss

Overscroll Behavior

src/docs/overscroll-behavior.mdx

latest5.7 KB
Original Source

import { ApiTable } from "@/components/api-table.tsx"; import { Example } from "@/components/example.tsx"; import { Figure } from "@/components/figure.tsx"; import { ResponsiveDesign } from "@/components/content.tsx";

export const title = "overscroll-behavior"; export const description = "Utilities for controlling how the browser behaves when reaching the boundary of a scrolling area.";

<ApiTable rows={[ ["overscroll-auto", "overscroll-behavior: auto;"], ["overscroll-contain", "overscroll-behavior: contain;"], ["overscroll-none", "overscroll-behavior: none;"], ["overscroll-x-auto", "overscroll-behavior-x: auto;"], ["overscroll-x-contain", "overscroll-behavior-x: contain;"], ["overscroll-x-none", "overscroll-behavior-x: none;"], ["overscroll-y-auto", "overscroll-behavior-y: auto;"], ["overscroll-y-contain", "overscroll-behavior-y: contain;"], ["overscroll-y-none", "overscroll-behavior-y: none;"], ]} />

Examples

Preventing parent overscrolling

Use the overscroll-contain utility to prevent scrolling in the target area from triggering scrolling in the parent element, but preserve "bounce" effects when scrolling past the end of the container in operating systems that support it:

<Figure hint="Scroll to see behavior"> <Example padding={false}> { <div className="h-48 space-y-4 overflow-auto overscroll-contain p-8 text-gray-600 dark:bg-gray-800 dark:text-gray-400"> <p children={` Well, let me tell you something, funny boy. Y'know that little stamp, the one that says "New York Public Library"? Well that may not mean anything to you, but that means a lot to me. One whole hell of a lot.`} /> <p children={` Sure, go ahead, laugh if you want to. I've seen your type before: Flashy, making the scene, flaunting convention. Yeah, I know what you're thinking. What's this guy making such a big stink about old library books? Well, let me give you a hint, junior.`} /> <p children={` Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve better?`} /> </div> } </Example>
html
<!-- [!code classes:overscroll-contain] -->
<div class="overscroll-contain ...">Well, let me tell you something, ...</div>
</Figure>

Preventing overscroll bouncing

Use the overscroll-none utility to prevent scrolling in the target area from triggering scrolling in the parent element, and also prevent "bounce" effects when scrolling past the end of the container:

<Figure hint="Scroll to see behavior"> <Example padding={false}> { <div className="h-48 space-y-4 overflow-auto overscroll-none p-8 text-gray-600 dark:bg-gray-800 dark:text-gray-400"> <p children={` Well, let me tell you something, funny boy. Y'know that little stamp, the one that says "New York Public Library"? Well that may not mean anything to you, but that means a lot to me. One whole hell of a lot.`} /> <p children={` Sure, go ahead, laugh if you want to. I've seen your type before: Flashy, making the scene, flaunting convention. Yeah, I know what you're thinking. What's this guy making such a big stink about old library books? Well, let me give you a hint, junior.`} /> <p children={` Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve better?`} /> </div> } </Example>
html
<!-- [!code classes:overscroll-none] -->
<div class="overscroll-none ...">Well, let me tell you something, ...</div>
</Figure>

Using the default overscroll behavior

Use the overscroll-auto utility to make it possible for the user to continue scrolling a parent scroll area when they reach the boundary of the primary scroll area:

<Figure hint="Scroll to see behavior"> <Example padding={false}> { <div className="h-48 space-y-4 overflow-auto overscroll-auto p-8 text-gray-600 dark:bg-gray-800 dark:text-gray-400"> <p children={` Well, let me tell you something, funny boy. Y'know that little stamp, the one that says "New York Public Library"? Well that may not mean anything to you, but that means a lot to me. One whole hell of a lot.`} /> <p children={` Sure, go ahead, laugh if you want to. I've seen your type before: Flashy, making the scene, flaunting convention. Yeah, I know what you're thinking. What's this guy making such a big stink about old library books? Well, let me give you a hint, junior.`} /> <p children={` Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve better?`} /> </div> } </Example>
html
<!-- [!code classes:overscroll-auto] -->
<div class="overscroll-auto ...">Well, let me tell you something, ...</div>
</Figure>

Responsive design

<ResponsiveDesign property="overscroll-behavior" defaultClass="overscroll-auto" featuredClass="overscroll-contain" />