我有一个将对象添加到数组中的表单,然后向用户提供所创建对象的预览。
我使用*ngFor循环数组,并将每个元素添加到屏幕底部。我的目标是在每个元素被添加后,将有一个自动滚动到页面底部
目前我使用的是setTimeOut函数,但我想知道有没有更好的方法?
this.createdAppointments.push(appointmentFormValues);
setTimeout(() => {
window.scrollTo(0, document.body.scrollHeight || document.documentElement.scrollHeight);
}, 1);
发布于 2019-01-14 04:41:46
您可以对新添加的项调用scrollIntoView方法,请参见https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
https://stackoverflow.com/questions/54172665
复制相似问题