当前位置:网站首页>详细介绍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
边栏推荐
- Qstype implementation of self drawing interface project practice (II)
- [fluent] dart data type map type (create map set | initialize map set | traverse map set)
- System Verilog implements priority arbiter
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
- 寒门再出贵子:江西穷县考出了省状元,做对了什么?
- 二、mock平台的扩展
- 【Leetcode】14. 最长公共前缀
- jsp 和 servlet 有什么区别?
- Executive engine module of high performance data warehouse practice based on Impala
- Connect Porsche and 3PL EDI cases
猜你喜欢

Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers

TCP congestion control details | 2 background

The macrogenome microbiome knowledge you want is all here (2022.7)

QWebEngineView崩溃及替代方案

Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era

Interpretation of key parameters in MOSFET device manual

Timing / counter of 32 and 51 single chip microcomputer

亚马逊云科技 Community Builder 申请窗口开启

Exploration of mobile application performance tools

Seven charts, learn to do valuable business analysis
随机推荐
LSF basic command
上传代码到远程仓库报错error: remote origin already exists.
One year is worth ten years
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
The macrogenome microbiome knowledge you want is all here (2022.7)
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
深度学习图像数据自动标注[通俗易懂]
IP address translation address segment
871. Minimum refueling times
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
Blog theme "text" summer fresh Special Edition
What will you do after digital IC Verification?
Role and function of uboot
Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
Qstype implementation of self drawing interface project practice (II)
寒门再出贵子:江西穷县考出了省状元,做对了什么?
使用知行之桥的API端口,提供资源供合作伙伴访问