Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

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

Joseph Milazzo426cb7f0beab
diff --git a/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts b/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts
index 7ea3e5665..318c6edb9 100644
--- a/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts
+++ b/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts
@@ -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() {
diff --git a/UI/Web/src/app/scroll.service.ts b/UI/Web/src/app/scroll.service.ts
index b49de4584..15e00b89d 100644
--- a/UI/Web/src/app/scroll.service.ts
+++ b/UI/Web/src/app/scroll.service.ts
@@ -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'
});