当前位置:网站首页>详细介绍scrollIntoView()方法属性
详细介绍scrollIntoView()方法属性
2022-07-02 14:42:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
因为工作中用到了锚点设置,常用的总是出问题,后来扒拉出了这个属性,详细研究了下方便日后使用
介绍scrollIntoView()的详细属性
简介
该scrollIntoView()方法将调用它的元素滚动到浏览器窗口的可见区域。
PS:根据其他元素的布局,元素可能无法完全滚动到顶部或底部。
TIPS:页面(容器)可滚动时才有用!
语法
element.scrollIntoView(); // 等同于element.scrollIntoView(true)
element.scrollIntoView(alignToTop); //布尔参数
element.scrollIntoView(scrollIntoViewOptions); //对象参数语法参数
alignToTop | [可选],目前之前这个参数得到了良好的支持 |
|---|---|
true | 元素的顶部将对齐到可滚动祖先的可见区域的顶部。对应于scrollIntoViewOptions: {block: "start", inline: "nearest"}。这是默认值 |
false | 元素的底部将与可滚动祖先的可见区域的底部对齐。对应于scrollIntoViewOptions: {block: "end", inline: "nearest"}。 |
scrollIntoViewOptions | [可选],目前这个参数浏览器对它的支持并不好,可以查看下文兼容性详情 |
|---|---|
behavior | [可选]定义过渡动画。"auto","instant"或"smooth"。默认为"auto"。 |
block | [可选] "start","center","end"或"nearest"。默认为"center"。 |
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"});应用场景
URL中hash标记的进化
- 聊天窗口滚动显示最新的消息
- 往一个列表添加item后滚动显示最新的添加的item
- 回到顶部(#)
- 滚动到指定位置(#xxx)
浏览器兼容性
特征 | Chrome | Firefox | Safari | Edge | IE | Opera |
|---|---|---|---|---|---|---|
基本支持( alignToTop ) | yes | yes | yes | yes | yes | yes |
scrollIntoViewOptions | yes | yes | 5.1[1] | 12[1] | 9[1] | 48[2] |
注意:不支持"smooth"行为或"center"选项。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148024.html原文链接:https://javaforall.cn
边栏推荐
- Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
- 超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
- Experience home office, feel the completion of the project | community essay solicitation
- 社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
- JS delete substring in string
- Eye of depth (III) -- determinant of matrix
- Amazon cloud technology community builder application window opens
- Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
- Error when uploading code to remote warehouse: remote origin already exists
- What will you do after digital IC Verification?
猜你喜欢

Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
![[essay solicitation activity] Dear developer, RT thread community calls you to contribute](/img/31/11409606718e0f4837f4cc572172a3.png)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute

剑指 Offer 26. 树的子结构

七张图,学会做有价值的经营分析

【Leetcode】14. 最长公共前缀
![[fluent] dart data type map type (create map set | initialize map set | traverse map set)](/img/02/75d21470ea0ae4cd3d17696a93d1ca.jpg)
[fluent] dart data type map type (create map set | initialize map set | traverse map set)

The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?

Qstype implementation of self drawing interface project practice (II)

Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements

Geoserver: publishing PostGIS data sources
随机推荐
Blog theme "text" summer fresh Special Edition
Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
Believe in yourself and finish the JVM interview this time
Easy language ABCD sort
默认浏览器设置不了怎么办?
dstat使用[通俗易懂]
Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
vscode设置删除行快捷键[通俗易懂]
Shutter: action feedback
相信自己,这次一把搞定JVM面试
电脑自带软件使图片底色变为透明(抠图白底)
System Verilog implements priority arbiter
深度之眼(三)——矩阵的行列式
One year is worth ten years
Geoserver: publishing PostGIS data sources
Executive engine module of high performance data warehouse practice based on Impala
What is generics- Introduction to generics
Flutter: 动作反馈