Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. Web API
  3. Element
  4. Element.scrollBy()

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

Element.scrollBy()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年1月.

scrollBy() 方法是使得元素滚动一段特定距离的Element 接口。

Syntax

element.scrollBy(x-coord, y-coord);element.scrollBy(options)

Parameters

  • x-coord 是元素要在横轴上滚动的距离。
  • y-coord 是元素要在纵轴上滚动的距离。

- or -

例子

js
// 让元素滚动element.scrollBy(300, 300);

使用options:

js
element.scrollBy({  top: 100,  left: 100,  behavior: "smooth",});

规范

Specification
CSSOM View Module
# dom-element-scrollby

浏览器兼容性

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp