Javascript scrollIntoView() 中间对齐?

标签 javascript js-scrollintoview

Javascript .scrollIntoView(boolean) 只提供两个对齐选项。

  1. 底部

如果我想这样 ScrollView 怎么办。我想将特定元素放在页面中间的某处?

最佳答案

试试这个:

 document.getElementById('myID').scrollIntoView({
            behavior: 'auto',
            block: 'center',
            inline: 'center'
        });

有关更多信息和选项,请参阅此处:https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

关于Javascript scrollIntoView() 中间对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8922107/

相关文章:

javascript - Google Apps 脚本应用程序突然执行缓慢/出错

javascript - 使用 block 中心调用scrollIntoView(...) 不起作用

javascript - 自动滚动到页面底部

javascript - 如何知道滚动到元素是用 Javascript 完成的?

javascript - Node.JS 中的 ECMAScript 6 模块

javascript - 我的 JSON feed 有什么问题?

Javascript - 比较对象并在新对象中存储差异

javascript - 使用 z-index 堆叠 XHTML 元素

python - chromedriver 版本 >74 时出现 MoveTargetOutOfBoundsException 问题

javascript - 如何获得一致的 ScrollIntoView 行为