Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element.scrollIntoView() #57

Open
Lee981265 opened this issue Nov 7, 2020 · 0 comments
Open

Element.scrollIntoView() #57

Lee981265 opened this issue Nov 7, 2020 · 0 comments

Comments

@Lee981265
Copy link
Member

Lee981265 commented Nov 7, 2020

定义

让当前的元素滚动到浏览器窗口的可视区域内。

语法

element.scrollIntoView(); // 等同于element.scrollIntoView(true) 
element.scrollIntoView(alignToTop); // Boolean型参数 
element.scrollIntoView(scrollIntoViewOptions); // Object型参数

参数

alignToTop可选

一个Boolean值:

  • 如果为true,元素的顶端将和其所在滚动区的可视区域的顶端对齐。相应的 scrollIntoViewOptions: {block: "start", inline: "nearest"}。这是这个参数的默认值。
  • 如果为false,元素的底端将和其所在滚动区的可视区域的底端对齐。相应的scrollIntoViewOptions: {block: "end", inline: "nearest"}

scrollIntoViewOptions可选

一个包含下列属性的Object:

  • behavior
    定义动画过渡效果, "auto""smooth" 之一。默认为 "auto"
  • **block **
    定义垂直方向的对齐, "start", "center", "end", 或 "nearest"之一。默认为 "end"。
  • behavior
    定义动画过渡效果, "auto""smooth" 之一。默认为 "auto"
  • inline
    定义水平方向的对齐, "start", "center", "end", 或 "nearest"之一。默认为 nearest"

示例

var element = document.getElementById("box");
 
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "instant", block: "end", inline: "nearest"});

兼容不支持

  • Safari on iOS
  • ie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant