Skip to content

Commit a4887c3

Browse files
committed
Fix: Some errors in scroll reading
1 parent dfd6c74 commit a4887c3

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
- Manga mode not working in epub [`a901754`](https://github.com/ollm/OpenComic/commit/a901754a4274687cddbfa3820ca3667b8b80e6ee)
1919
- eBook not working with decimal device pixel ratio (1.5, 2.5, etc) [`4962724`](https://github.com/ollm/OpenComic/commit/496272442747e466638e890a187f84b100deda14)
2020
- Blurry cover/poster images [`23ae46d`](https://github.com/ollm/OpenComic/commit/23ae46d3d77847f5262f10799a21d7ee0141b226)
21-
- Using the first image as a poster does not work
21+
- Using the first image as a poster does not work [`fd6c748`](https://github.com/ollm/OpenComic/commit/dfd6c748090088109416b847a5e7581d80e36ea7)
22+
- Some errors in scroll reading
2223

2324
## [v1.1.0](https://github.com/ollm/OpenComic/releases/tag/v1.1.0) (13-01-2024)
2425

scripts/reading.js

+52-18
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ function disposeImages(data = false)
418418
{
419419
let image = image0[i];
420420

421-
image.style.height = imageHeight0+'px';
422-
image.style.width = imageWidth0+'px';
421+
image.style.height = app.roundDPR(imageHeight0)+'px';
422+
image.style.width = app.roundDPR(imageWidth0)+'px';
423423
image.style.marginLeft = app.roundDPR(marginLeft0)+'px';
424424
image.style.marginTop = app.roundDPR(marginTop0)+'px';
425425
image.style.marginBottom = app.roundDPR((readingViewIs('scroll') && ((+key1) + 1) == indexNum) ? marginVertical : 0)+'px';
@@ -481,8 +481,8 @@ function disposeImages(data = false)
481481
{
482482
let image = image1[i];
483483

484-
image.style.height = imageHeight1+'px';
485-
image.style.width = imageWidth1+'px';
484+
image.style.height = app.roundDPR(imageHeight1)+'px';
485+
image.style.width = app.roundDPR(imageWidth1)+'px';
486486
image.style.marginLeft = app.roundDPR(marginLeft1)+'px';
487487
image.style.marginTop = app.roundDPR(marginTop1)+'px';
488488
image.style.marginBottom = app.roundDPR((readingViewIs('scroll') && ((+key1) + 1) == indexNum) ? marginVertical : 0)+'px';
@@ -586,8 +586,8 @@ function disposeImages(data = false)
586586
{
587587
let image = image0[i];
588588

589-
image.style.height = imageHeight+'px';
590-
image.style.width = imageWidth+'px';
589+
image.style.height = app.roundDPR(imageHeight)+'px';
590+
image.style.width = app.roundDPR(imageWidth)+'px';
591591
image.style.marginLeft = app.roundDPR(marginLeft)+'px';
592592
image.style.marginTop = app.roundDPR(marginTop)+'px';
593593
image.style.marginBottom = app.roundDPR((readingViewIs('scroll') && ((+key1) + 1) == indexNum) ? marginVertical : 0)+'px';
@@ -715,11 +715,24 @@ function calculateView()
715715
}
716716
}
717717

718-
var previousScrollTop = 0, previousContentHeight = 0;
718+
var previousScrollTop = 0, previousScrollHeight = 0, previousContentHeight = 0, stayInLineData = {scrollTop: false, scrollHeight: false, heigth: false, setTimeout: false};
719+
720+
function getPreviusContentSize()
721+
{
722+
if(!readingViewIs('scroll')) return;
723+
724+
let contentRight = template._contentRight();
725+
let content = contentRight.firstElementChild;
726+
let rect = content.getBoundingClientRect();
727+
728+
previousContentHeight = rect.height;
729+
previousScrollHeight = content.scrollHeight;
730+
previousScrollTop = content.scrollTop;
731+
}
719732

720733
function stayInLine()
721734
{
722-
if(readingViewIs('slide') || (readingViewIs('scroll') && !_config.readingViewAdjustToWidth && !_config.readingWebtoon))
735+
if(readingViewIs('slide')/* || (readingViewIs('scroll') && !_config.readingViewAdjustToWidth && !_config.readingWebtoon)*/)
723736
{
724737
if(currentIndex < 1 && dom.previousComic())
725738
showPreviousComic(1, false);
@@ -730,12 +743,31 @@ function stayInLine()
730743
}
731744
else if(readingViewIs('scroll'))
732745
{
733-
if(currentIndex < 1 && dom.previousComic())
734-
showPreviousComic(1, false);
735-
else if(currentIndex > contentNum && dom.nextComic())
736-
showNextComic(1, false);
746+
let contentRight = template._contentRight();
747+
let content = contentRight.firstElementChild;
748+
let rect = content.getBoundingClientRect();
749+
750+
disableOnScroll(true);
751+
752+
if(stayInLineData.scrollTop === false)
753+
{
754+
stayInLineData = {scrollTop: previousScrollTop, scrollHeight: previousScrollHeight, height: previousContentHeight, setTimeout: false};
755+
}
737756
else
738-
goToIndex(currentIndex, false, currentPageVisibility);
757+
{
758+
clearTimeout(stayInLineData.setTimeout);
759+
stayInLineData.setTimeout = setTimeout(function(){
760+
761+
previousContentHeight = stayInLineData.height;
762+
previousScrollHeight = stayInLineData.scrollHeight;
763+
stayInLineData = {scrollTop: false, scrollHeight: false, setTimeout: false};
764+
765+
disableOnScroll(false);
766+
767+
}, 400);
768+
}
769+
770+
content.scrollTop = ((stayInLineData.scrollTop + (stayInLineData.height / 2)) / stayInLineData.scrollHeight * content.scrollHeight) - (rect.height / 2);
739771
}
740772
}
741773

@@ -1428,6 +1460,7 @@ function onScroll(event)
14281460
scrollPart = ((rightSize.height - contentHeightRes) - rightSize.height / pageVisibility);
14291461

14301462
currentPageVisibility = Math.round((previousScrollTop - (imagesFullPosition[selIndex][0].top - readingMargin().top)) / scrollPart);
1463+
if(currentPageVisibility < 0) currentPageVisibility = 0;
14311464

14321465
if(currentIndex != selIndex + 1)
14331466
{
@@ -2508,7 +2541,7 @@ function resized()
25082541
generateEbookPagesDelayed();
25092542
}
25102543

2511-
previousContentHeight = template.contentRight().children('div').children('div').height();
2544+
// getPreviusContentSize();
25122545
}
25132546

25142547
var hiddenContentLeft = false, hiddenBarHeader = false, hideContentDisableTransitionsST = false, hideContentST = false, hideContentRunningST = false, shownContentLeft = false, shownBarHeader = false;
@@ -2629,6 +2662,7 @@ var activeOnScroll = true;
26292662
function disableOnScroll(disable = true)
26302663
{
26312664
activeOnScroll = !disable;
2665+
if(!disable) getPreviusContentSize();
26322666
}
26332667

26342668
function setReadingDragScroll(dragScroll)
@@ -3976,7 +4010,7 @@ async function generateEbookPages(end = false, reset = false, fast = false, imag
39764010
goToIndex(newIndex, false, end, end);
39774011

39784012
if(readingViewIs('scroll'))
3979-
previousContentHeight = template.contentRight().children('div').children('div').height();
4013+
getPreviusContentSize();
39804014

39814015
setTimeout(function(){onScroll.call(template._contentRight().firstElementChild)}, 500);
39824016

@@ -4899,7 +4933,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
48994933
goToIndex(newIndex, false, end, end);
49004934

49014935
if(readingViewIs('scroll'))
4902-
previousContentHeight = template.contentRight().children('div').children('div').height();
4936+
getPreviusContentSize();
49034937

49044938
setTimeout(function(){onScroll.call(template._contentRight().firstElementChild)}, 500);
49054939

@@ -4946,7 +4980,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
49464980
goToIndex(newIndex, false, end, end);
49474981

49484982
if(readingViewIs('scroll'))
4949-
previousContentHeight = template.contentRight().children('div').children('div').height();
4983+
getPreviusContentSize();
49504984

49514985
setTimeout(function(){onScroll.call(template._contentRight().firstElementChild)}, 500);
49524986

@@ -4980,7 +5014,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
49805014
goToIndex(newIndex, false, end, end);
49815015

49825016
if(readingViewIs('scroll'))
4983-
previousContentHeight = template.contentRight().children('div').children('div').height();
5017+
getPreviusContentSize();
49845018

49855019
setTimeout(function(){onScroll.call(template._contentRight().firstElementChild)}, 500);
49865020

scripts/reading/render.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function resized(doublePage = false)
172172
if(scaleMagnifyingGlass) setRenderQueue(doublePage ? 3 : 2, doublePage ? 4 : 2, false, true);
173173
setRenderQueue(maxPrev, maxNext);
174174

175-
}, 800);
175+
}, 400);
176176

177177
}, 200);
178178
}
@@ -326,6 +326,10 @@ async function render(index, _scale = false, magnifyingGlass = false)
326326
{
327327
canvas.style.width = Math.round(isRendered.width)+'px';
328328
canvas.style.height = Math.round(isRendered.height)+'px';
329+
330+
ocImg.style.width = Math.round(isRendered.width)+'px';
331+
ocImg.style.height = Math.round(isRendered.height)+'px';
332+
329333
ocImg.replaceChildren(canvas);
330334
}
331335
}

0 commit comments

Comments
 (0)