Skip to content
全部文档

overscroll-behavior

用于控制浏览器到达滚动区域边界时行为的工具类。

快速参考

属性
overscroll-autooverscroll-behavior: auto;
overscroll-containoverscroll-behavior: contain;
overscroll-noneoverscroll-behavior: none;
overscroll-x-autooverscroll-behavior-x: auto;
overscroll-x-containoverscroll-behavior-x: contain;
overscroll-x-noneoverscroll-behavior-x: none;
overscroll-y-autooverscroll-behavior-y: auto;
overscroll-y-containoverscroll-behavior-y: contain;
overscroll-y-noneoverscroll-behavior-y: none;

示例

防止父级过度滚动

使用 overscroll-contain 工具类,防止目标区域内的滚动触发父元素滚动,但在支持该效果的操作系统中,滚动超过容器末端时仍保留「回弹」效果:

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.

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.

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?

html
<!-- [!code classes:overscroll-contain] -->
<div class="overscroll-contain ...">Well, let me tell you something, ...</div>

防止过度滚动回弹

使用 overscroll-none 工具类,防止目标区域内的滚动触发父元素滚动,同时在滚动超过容器末端时也阻止「回弹」效果:

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.

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.

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?

html
<!-- [!code classes:overscroll-none] -->
<div class="overscroll-none ...">Well, let me tell you something, ...</div>

使用默认过度滚动行为

使用 overscroll-auto 工具类,让用户到达主滚动区域边界时可以继续滚动父级滚动区域:

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.

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.

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?

html
<!-- [!code classes:overscroll-auto] -->
<div class="overscroll-auto ...">Well, let me tell you something, ...</div>

响应式设计

使用 md: 等断点变体作为 overscroll-behavior 工具类的前缀,即可仅在中等及以上屏幕尺寸下应用该工具类:

html
<div class="overscroll-auto md:overscroll-contain ...">
 <!-- ... -->
</div>

了解如何使用变体,请参阅变体文档

文档译文以 MIT 协议授权;原文版权归 Tailwind Labs。湘ICP备2026005453号-2