gpt4 book ai didi

javascript - 如何溢出自动对焦的最后一个元素

转载 作者:行者123 更新时间:2023-12-03 12:21:47 24 4
gpt4 key购买 nike

我开发Todo App。如果添加到新元素,滚动条将不会聚焦在页面底部。我怎么解决这个问题 ?
How can I automatically fix it to the bottom all the time?

最佳答案

添加后可以使用Element.scrollIntoView()。
例如:

function addElement(text) {
// create a new element
const element = document.createElement('p');
element.innerText = text;

// get the list where you want to add the element
const list = document.getElementById("myList");
list.appendChild(element);

// scroll to it
element.scrollIntoView();
}
有关兼容性的更多信息,请查看 https://developer.mozilla.org/de/docs/Web/API/Element/scrollIntoView,它被标记为实验性的,但是所有常见的浏览器都支持它。

关于javascript - 如何溢出自动对焦的最后一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65539856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com