当前位置:网站首页>Mobile phone side scroll to page to specify location
Mobile phone side scroll to page to specify location
2022-07-30 07:52:00 【cplvfx】
scrollIntoViewOptions is very useful, but currently only supported by Chrome and FireFox, but can be implemented by other plugins (smoothscroll-polyfill)span>
Example
document.getElementById('content').scrollIntoView({block: 'start',inline: 'nearest',behavior: 'smooth'})
Documentation
The first solution: the method parameter is passed "alignToTop"
Previously this parameter was well supported
scrollIntoView(alignToTop); // Boolean parameter
alignToTop
A Boolean value:
- If true, the top of the element will be aligned with the top of the visible area of the scroll area it is in.
- If false, the bottom of the element will be aligned with the bottom of the visible area of the scroll area it is in.
true : The top of the element will be aligned to the top of the scrollable ancestor's visible area.Corresponds to scrollIntoViewOptions: {block: "start", inline: "nearest"} which is the defaultfalse: The bottom of the element will be aligned with the bottom of the scrollable ancestor's visible area.Corresponds to scrollIntoViewOptions: {block: "end", inline: "nearest"}.
Use
document.getElementById('content').scrollIntoView(true);
The second solution (such as the example): pass "scrollIntoViewOptions" as a method parameter
Currently this parameter browser does not support it well, you can check the compatibility below
element.scrollIntoView(scrollIntoViewOptions); // Object parameter
behavior: [Optional] Define the transition animation."auto", "instant" or "smooth".Defaults to "auto".block : [optional] "start" (top), "center" (center), "end" (tail) or "nearest".Defaults to "center".inline: [optional] "start", "center", "end" or "nearest".Defaults to "nearest".
Use
document.getElementById('content').scrollIntoView({block: 'start',inline: 'nearest',behavior: 'smooth'})
Reference
http://mssn.midea.com/ask/?/article/230
https://zhuanlan.zhihu.com/p/342205449
边栏推荐
猜你喜欢
引导过程与服务控制
STL源码剖析:bound friend template friend代码测试和理解
STL源码剖析:迭代器的概念理解,以及代码测试。
大厂年薪50w+招聘具有测试平台开发能力的测试工程师
The CTO said I was not advised to use SELECT *, why is that?
npm安装nodejs环境配置
Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities
DNS域名解析服务
PXE高效批量网络装机
Graph Computing 101: Types, Languages, and Systems of Graph Computing
随机推荐
STL源码剖析:临时对象的代码测试和理解
搭建vsftpd服务并实现本地用户访问
Graph Computing 101: Types, Languages, and Systems of Graph Computing
测试开发工程师成长日记001 - 敏捷测试、CI/CD/CT、DecOps的一些介绍
The CTO said I was not advised to use SELECT *, why is that?
DHCP原理与配置
Advanced multi-threading (CountDownLatch, deadlock, thread-safe collection class)
空间平面相交的直线的计算及其源码
阿里一面:多线程顺序运行有多少种方法?
From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities
测试开发工程师成长日记016 - 关于提测的那些事
MongoDB-CUD没有R
Linx常见目录&文件管理命令&VI编辑器使用 介绍
npm安装nodejs环境配置
多线程基础(概念,创建,中断)
Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
prometheus-Federation机制配置
软件测试开发:发送第一封测试报告邮件
多线程进阶(CountDownLatch,死锁,线程安全集合类)