You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

滚动到底部时window.scrollY返回值小于文档总高度的问题求助

滚动到底部时window.scrollY返回值小于文档总高度的问题求助

各位好,我正在开发一个自定义PDF查看器,它会把PDF页面渲染成垂直排列的图片,但现在遇到了一个滚动位置不一致的问题,想请大家帮忙看看:

  • 实际文档总高度:document.documentElement.scrollHeight返回的是10016px(这个数值是所有图片高度的总和)
  • 滚动到底部时的最终位置:window.scrollY最多只能到9410px,达不到文档总高度对应的位置

下面是我的HTML渲染代码:

<div #canvas *ngFor="let image of canvasItems; let i = index" style="height: 100%" [ngStyle]="{'width': isGedPreview ? '100%' : ''}">
  <img [src]="image" alt="pdf" [id]="'image-' + i" class="pdf-page" [ngStyle]="{'max-width': getMaxWidth(), 'width': getWidth()}" (load)="updatePageHeights(i)">
  <br>
</div>

还有监听滚动事件的代码:

@HostListener('window:scroll', ['$event']) onScroll() {
  if (this.canSkipScrollAdjustment()) {
    return;
  }
  const scrollPosition = window.scrollY;
  const scrollHeigth = document.documentElement.scrollHeight;
  console.log("scrollposition, ", scrollPosition); // 9410px
  console.log("scrollHeigth, ", scrollHeigth); // 10016px
}

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 09:43:01