Fixed a bug where loading page on book reader wouldn't scroll to last position (#907)

This commit is contained in:
Joseph Milazzo 2022-01-07 07:42:22 -08:00 committed by GitHub
parent 6afbf5f08f
commit 426cb7f0be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -301,8 +301,6 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
.pipe(debounceTime(200), takeUntil(this.onDestroy)).subscribe((event) => {
if (this.isLoading) return;
console.log('Scroll');
// Highlight the current chapter we are on
if (Object.keys(this.pageAnchors).length !== 0) {
// get the height of the document so we can capture markers that are halfway on the document viewport
@ -745,9 +743,9 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
if (part !== undefined && part !== '') {
this.scrollTo(part);
} else if (scrollTop !== undefined && scrollTop !== 0) {
this.scrollService.scrollTo(scrollTop);
this.scrollService.scrollTo(scrollTop, this.reader.nativeElement);
} else {
this.scrollService.scrollTo(0);
this.scrollService.scrollTo(0, this.reader.nativeElement);
}
}
@ -971,7 +969,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
if (element === null) return;
this.scrollService.scrollTo(element.getBoundingClientRect().top + window.pageYOffset + TOP_OFFSET);
this.scrollService.scrollTo(element.getBoundingClientRect().top + window.pageYOffset + TOP_OFFSET, this.reader.nativeElement);
}
toggleClickToPaginate() {

View File

@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { ElementRef, Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
@ -13,8 +13,8 @@ export class ScrollService {
|| document.body.scrollTop || 0);
}
scrollTo(top: number) {
window.scroll({
scrollTo(top: number, el: Element | Window = window) {
el.scroll({
top: top,
behavior: 'smooth'
});