ScrollToOptions.behavior - Web APIs 编辑
The behavior
property of the ScrollToOptions
dictionary specifies whether the scrolling should animate smoothly, or happen instantly in a single jump.
This is actually defined on the ScrollOptions
dictionary, which is implemented by ScrollToOptions
.
Syntax
behavior: ScrollBehavior
Value
An enum, the value of which can be one of the following:
smooth
: The scrolling animates smoothly.auto
: The scrolling happens in a single jump.
Examples
In our scrolltooptions example (see it live) we include a form that allows the user to enter three values — two numbers representing the left and top properties (i.e. the positions to scroll to along the X and Y axes), and a checkbox indicating whether they want smooth scrolling enabled or not.
When the form is submitted, an event handler is run that puts the entered values into a ScrollToOptions dictionary, and then invokes the Window.ScrollTo()
method, passing the dictionary as a parameter:
form.addEventListener('submit', (e) => {
e.preventDefault();
var scrollOptions = {
left: leftInput.value,
top: topInput.value,
behavior: scrollInput.checked ? 'smooth' : 'auto'
}
window.scrollTo(scrollOptions);
});
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'behavior' in that specification. | Working Draft |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论