当前位置:网站首页>详细介绍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
边栏推荐
- 一年頂十年
- [essay solicitation activity] Dear developer, RT thread community calls you to contribute
- Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
- 超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
- Connect Porsche and 3PL EDI cases
- 什么是泛型?- 泛型入门篇
- [fluent] dart data type map type (create map set | initialize map set | traverse map set)
- 有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
- IP地址转换地址段
- Digital IC hand tearing code -- voting device
猜你喜欢
寒门再出贵子:江西穷县考出了省状元,做对了什么?
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
871. 最低加油次数
Digital IC hand tearing code -- voting device
13、Darknet YOLO3
TCP拥塞控制详解 | 2. 背景
[cloud native] briefly talk about the understanding of flume, a massive data collection component
【Leetcode】13. Roman numeral to integer
使用知行之桥的API端口,提供资源供合作伙伴访问
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
随机推荐
OpenHarmony如何启动远程设备的FA
GeoServer:发布PostGIS数据源
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
Ap和F107数据来源及处理
vscode设置删除行快捷键[通俗易懂]
移动应用性能工具探索之路
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
ssb门限_SSB调制「建议收藏」
Does digicert SSL certificate support Chinese domain name application?
宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
Executive engine module of high performance data warehouse practice based on Impala
你想要的宏基因组-微生物组知识全在这(2022.7)
[error record] error -32000 received from application: there are no running service protocol
Vscode setting delete line shortcut [easy to understand]
JS delete substring in string
ThreadLocal
js删除字符串中的子串
One year is worth ten years