javascript - 滚动到溢出 :auto 中包含的 div

标签 javascript jquery html

我有这个:

<div id="parent" style="overflow:auto">
   ...
   <div id="test">Hello</div>
   ...
</div>

我的问题是:如何滚动父 div 以将测试 div 作为父 div 的第一行?

最佳答案

如果您不想使用插件,请参阅 element.scrollIntoView :

$("#test").get(0).scrollIntoView();

// Plain ol' JS:
document.getElementById("test").scrollIntoView();

关于javascript - 滚动到溢出 :auto 中包含的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2569421/

相关文章:

javascript - 在 react 中如何避免这种类型的错误?

javascript - 作为参数传递时函数不起作用

javascript - 如何使用角色 "li"作为触发器将类添加到 ="alter"元素

jquery - CSS 样式仅适用于不适用于选择器的元素

javascript - 无法将整个 HTML 内容放入 iframe

javascript - 如果 URL 相同,则将选项值更改为已选择

javascript - 在 chrome.storage.local.set 中使用可变键

javascript - Webkit- css 随持续时间变化

html - 图片上的文字

javascript - 正则表达式 - 如何在不在 html 内部时替换 css