当前位置:网站首页>手机端滚动至页面指定位置
手机端滚动至页面指定位置
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
边栏推荐
- AI元学习引入神经科学,医疗效果有望精准提升
- Devops基本概念和原理
- Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
- 远程连接服务器的MySql
- Redis6的数据类型
- 大厂年薪50w+招聘具有测试平台开发能力的测试工程师
- Distance calculation from space vertex to straight line and its source code
- debian problem
- Install MySQL under Linux (centos7)
- SE_01
猜你喜欢

Linux(centos7)下安装MySQL

flask项目快速搭建部署gunicorn+supervisor

DHCP原理与配置

prometheus-federation-tls加密

Rodrigues:旋转矩阵的向量表达

测试开发工程师成长日记003 - 接口自动化框架搭建

The calculation proof of the intersection of the space line and the plane and its source code

AI元学习引入神经科学,医疗效果有望精准提升

Linx common directory & file management commands & VI editor usage introduction

远程连接服务器的MySql
随机推荐
MySQL common commands and mysqldump backup
PXE高效批量网络装机
相机坐标系,世界坐标系,像素坐标系三者转换,以及OPENGLDEFocal Length和Opengl 的 Fov转换
测试开发工程师成长日记002 - 从0开始做接口自动化
Test development engineer diary 002 - starting from 0 interface automation
Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps
Waterfall flow (custom layout implementation)
DNS域名解析服务
MongoDB-介绍,数据类型,基本语句
DHCP principle and configuration
Mastering JESD204B (2) – Debugging of AD6676
prometheus-tls加密
debian vsftpd + ssl
Devops基本概念和原理
Deploy GraphScope with Helm
Redis download and installation
作为测试leader,考察求职者的几个方面
DHCP原理与配置
Advanced multi-threading (CountDownLatch, deadlock, thread-safe collection class)
测开基础知识01