目录

style scrollBehavior 属性

示例

为页面添加平滑滚动效果:

document.documentElement.style.scrollBehavior = "smooth";
亲自试一试 »

描述

scrollBehavior 属性指定当用户单击可滚动框中的链接时是否平滑地设置滚动位置动画,而不是直接跳转。


浏览器支持

Property
scrollBehavior 61.0 79.0 36.0 14.0 48.0

语法

object.style.scrollBehavior = "auto|smooth|initial|inherit"

属性值

Value Description
auto Default. Allows a straight jump "scroll effect" between elements within the scrolling box.
smooth Allows a smooth animated "scroll effect" between elements within the scrolling box.
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

相关页面

CSS 参考:滚动行为属性