【问题标题】:.scrollIntoView shifts page slightly to Left.scrollIntoView 将页面稍微向左移动
【发布时间】:2019-12-11 17:37:20
【问题描述】:

我安装了一个 .scrollIntoView 元素并指定了内容必须滚动到的位置,即 .但是,当我在网站上对其进行测试时,单击触发 scrollIntoView 功能的按钮后,该功能运行良好,它滚动到所需位置并显示包含它的所有内容,但是 WHOLE 页面略微向 LEFT 移动。

注意:在桌面上不是很明显,但在移动设备或平板电脑上很明显左侧大约 10% 的内容从屏幕上被剪掉了)。

关于如何防止整个页面向左移动的任何想法?


.

  <div class="scrolltohere"></div>



<script>
function myFunction() {
  var elmnt = document.getElementsByClassName("scrolltohere");
  elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "start"}); 
}
</script>

【问题讨论】:

标签: javascript html css


【解决方案1】:

我得到了答案,所以基本上问题是 inline 设置为“开始”,将其删除或将其更改为“最近”解决了页面左移问题。

从此改变

  elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "start"}); 

到这里

elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 2021-01-29
    • 2016-06-24
    相关资源
    最近更新 更多