javascript - .scrollIntoView 将页面稍微向左移动
问题描述
我安装了一个.scrollIntoView元素并指定了内容必须滚动到的位置,即 . 但是,当我在网站上对其进行测试时,单击触发scrollIntoView功能的按钮后,该功能运行良好,它滚动到所需位置并显示包含它的所有内容,但整个页面略微向左移动。
注意:在桌面上不是很明显,但在移动设备或平板电脑上很明显左侧大约 10% 的内容从屏幕上被剪掉了)。
关于如何防止整个页面向左移动的任何想法?
.
<div class="scrolltohere"></div>
<script>
function myFunction() {
var elmnt = document.getElementsByClassName("scrolltohere");
elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "start"});
}
</script>
解决方案
我得到了答案,所以基本上问题是内联被设置为“开始”,删除它或将其更改为“最近”解决了页面向左移动的问题。
从此改变
elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "start"});
对此
elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
推荐阅读
- r - 我在 R 中收到 nlme 包的功能错误
- python - 在 Python 中的进程之间共享列表的正确方法?
- react-native - React 本机应用程序需要时间来加载资产?
- python - python版本检查命令仅在用户模式下有效,不适用于root
- charles-proxy - 无法从使用 Charles 在 Android 上运行的特定应用程序获取 API 调用日志
- ajax - 集成 Paypal 时出现跨域请求被阻止错误
- php - 如何将特定结构数组转换为“树”结构数组?
- environment-variables - 无法在 Gatsby 构建中设置其他环境变量
- angular - 组件调用多个 API 时只调用一次拦截器
- angular - 如何仅在 *ngFor 完成加载后调用函数?