【发布时间】:2020-12-09 21:31:51
【问题描述】:
我有一个反应组件,需要在给定特定触发器的情况下滚动到底部。 Following the answers in this SO question 在这些方面似乎是一个不错且简单的解决方案(完整示例可以在链接的问题中找到):
const scrollToBottom = () => {
if (messagesEndRef.current) {
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
}
};
但是,在将应用程序嵌入 iFrame 后,结果发现这也会触发父页面滚动,这很糟糕。我尝试了this question 的答案中链接的解决方案的不同变体,但没有成功。
编辑:这些失败尝试的一些示例:
// document.documentElement.scrollTop = messagesEndRef.current.offsetTop;
// messagesEndRef.current.parentNode.scrollTop = messagesEndRef.current.offsetTop;
任何指向如何实现相同滚动行为但不影响 iFrame 父页面的指针将不胜感激。
【问题讨论】:
标签: javascript reactjs