如何滚动到底部的聚合物1.0纸抽屉面板

How to scroll to the bottom of a Polymer 1.0 paper-drawer-panel

本文关键字:聚合物 何滚动 滚动 底部      更新时间:2023-09-26

我使用纯聚合物/Javascript,需要滚动到我的主面板的底部。由于它是固定大小容器内的可滚动元素,典型的JS答案

window.scrollTo(0,document.body.scrollHeight);

找不到直接的解决方案,所以我自己贴了一个答案。希望对大家有所帮助:)

(基于我在这里发现的)

//Get the main paper-drawer-panel element
    a = document.querySelector("paper-drawer-panel [main]")
//use the undocumented scroller property and set it to the scroller's height
    a.scroller.scrollTop = a.scroller.scrollHeight

更新:

我还发现,如果你在面板中选择任何元素或容器,应该有滚动方法附加在它们上面,允许你根据所选元素滚动到面板的顶部或底部。

//Get the main paper-drawer-panel element
    a = document.querySelector("some-element-container-in-paper-panel");
// Passing in false scrolls to the bottom of the container, no param to the top.
    a.scrollIntoView(false)

我可能不会评论(我需要50点的东西),但scrollIntoView()是实验性技术。Chrome浏览器不支持