当前位置:网站首页>详细介绍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
边栏推荐
- 一年顶十年
- 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
- System Verilog implements priority arbiter
- Smart trash can (V) - light up OLED
- 亚马逊云科技 Community Builder 申请窗口开启
- Eye of depth (III) -- determinant of matrix
- Does digicert SSL certificate support Chinese domain name application?
- GeoServer:发布PostGIS数据源
- Detailed explanation of @accessories annotation of Lombok plug-in
- 伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
猜你喜欢

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

你想要的宏基因组-微生物组知识全在这(2022.7)

AP and F107 data sources and processing

OpenPose的使用

Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan

几行代码搞定RPC服务注册和发现

Smart trash can (V) - light up OLED

Timing / counter of 32 and 51 single chip microcomputer

博客主题 “Text“ 夏日清新特别版

linux安装postgresql + patroni 集群问题
随机推荐
博客主题 “Text“ 夏日清新特别版
Domestic relatively good OJ platform [easy to understand]
Sword finger offer 22 The penultimate node in the linked list
Exploration of mobile application performance tools
The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
LSF basic command
Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
QStyle实现自绘界面项目实战(二)
How to transfer business data with BorgWarner through EDI?
TCP congestion control details | 2 background
Youzan won the "top 50 Chinese enterprise cloud technology service providers" together with Tencent cloud and Alibaba cloud [easy to understand]
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
vscode设置删除行快捷键[通俗易懂]
Does digicert SSL certificate support Chinese domain name application?
System Verilog implements priority arbiter
【征文活动】亲爱的开发者,RT-Thread社区喊你投稿啦