当前位置:网站首页>手机端滚动至页面指定位置
手机端滚动至页面指定位置
2022-07-30 05:50:00 【cplvfx】
scrollIntoViewOptions是非常有用的,但是目前只有Chrome和FireFox可以支持,但是可以通过其他插件实现(smoothscroll-polyfill)
示例
document.getElementById('content').scrollIntoView({
block: 'start',
inline: 'nearest',
behavior: 'smooth'
})
文档
第一种方案:方法参数传 “alignToTop”
目前之前这个参数得到了良好的支持
scrollIntoView(alignToTop); // Boolean parameteralignToTop
一个Boolean值:
- 如果为true,元素的顶端将和其所在滚动区的可视区域的顶端对齐。
- 如果为false,元素的底端将和其所在滚动区的可视区域的底端对齐。
true :元素的顶部将对齐到可滚动祖先的可见区域的顶部。对应于scrollIntoViewOptions: {block: "start", inline: "nearest"} 这是默认值
false:元素的底部将与可滚动祖先的可见区域的底部对齐。对应于scrollIntoViewOptions: {block: "end", inline: "nearest"}。使用
document.getElementById('content').scrollIntoView(true);第二种方案(如示例):方法参数传 “scrollIntoViewOptions”
目前这个参数浏览器对它的支持并不好,可以查看下文兼容性
element.scrollIntoView(scrollIntoViewOptions); // Object parameterbehavior: [可选]定义过渡动画。"auto","instant"或"smooth"。默认为"auto"。 block :[可选] "start"(顶部),"center"(居中),"end"(尾部) 或"nearest"。默认为"center"。 inline:[可选] "start","center","end"或"nearest"。默认为"nearest"。
使用
document.getElementById('content').scrollIntoView({
block: 'start',
inline: 'nearest',
behavior: 'smooth'
})参考
http://mssn.midea.com/ask/?/article/230
https://zhuanlan.zhihu.com/p/342205449
边栏推荐
- Mastering JESD204B (1) – Debugging of AD6676
- Mastering JESD204B (3) – Debugging of AD6676
- MongoDB-CUD without R
- @Bean 与 @Component 用在同一个类上,会怎样?
- SE_01
- 计算矩阵的逆源码(使用伴随矩阵,3×3的矩阵)
- STL源码剖析:bound friend template friend代码测试和理解
- 空间顶点到直线的距离计算及其源码
- Application of graph computing in network security analysis
- 如何理解普吕克坐标(几何理解)
猜你喜欢

(GGG)JWT

Network Protocol 04 - Physical and Data Link Layers

测试开发工程师成长日记016 - 关于提测的那些事

Interactively compose graphs in GraphScope based on the JupyterLab plugin

npm安装nodejs环境配置

Build an intelligent network security management and control system for digital government

prometheus监控minio

Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)

空间平面相交的直线的计算及其源码

《心智社会》—马文·明斯基
随机推荐
STL源码剖析:临时对象的代码测试和理解
引导过程与服务控制
kubernetes搭建SonarQube进行代码扫描
空间平面相交的直线的计算及其源码
软件测试开发:发送第一封测试报告邮件
Polygon 3D(三维平面多边形)的法向量的计算(MeshLab默认的计算)
GNNLab: A Novel GNN System Based on Spatial Sharing Ideas
Test development engineer diary 002 - starting from 0 interface automation
你被MySQL 中的反斜杠 \\坑过吗?
STL source code analysis: conceptual understanding of iterators, and code testing.
GAIA-IR: Parallelized Graph Query Engine on GraphScope
Redis download and installation
Application of graph computing in network security analysis
Redis6的数据类型
测试开发工程师成长日记016 - 关于提测的那些事
Devops基本概念和原理
多线程进阶(锁策略,自旋+CAS,Synchronized,JUC,信号量)
舒尔补(schur completement)
Network Protocol 01 - Basic Concepts
prometheus-Federation机制配置