js原生如何获取可滚动元素中的子元素坐标值
要在可滚动元素(如
该 api 返回一个 domrect 对象,其中包含元素相对于其包含块的边界框的顶部、左、右和底部坐标值。
const popcontainer = document.getelementbyid('pop'); const lielements = popcontainer.queryselectorall('li[pdata]'); lielements.foreach((li) => { const boundingbox = li.getboundingclientrect(); console.log( `li element (pdata=${li.getattribute('pdata')}):`, `top: ${boundingbox.top}px, left: ${boundingbox.left}px` ); });
监测滚动事件
要监测
popContainer.addEventListener('scroll', () => { // Element has scrolled. });
以上就是JS原生如何获取可滚动元素内子元素的精确坐标?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号