@@ -543,28 +543,39 @@ function disposeImages(data = false)
543
543
}
544
544
}
545
545
546
+ var rightSize = { } ; // Right content size
547
+
546
548
function calculateView ( )
547
549
{
548
550
let contentRight = template . contentRight ( ) . get ( 0 ) ;
549
551
550
- let content = template . contentRight ( ) . children ( 'div' ) ;
551
- let contentWidth = template . contentRight ( ) . width ( ) ;
552
+ let content = contentRight . firstElementChild ;
553
+ let rect = content . getBoundingClientRect ( ) ;
554
+
555
+ rightSize = {
556
+ height : rect . height ,
557
+ width : rect . width ,
558
+ top : rect . top ,
559
+ left : rect . left ,
560
+ // readingRect: content.querySelector('.reading-body').getBoundingClientRect(),
561
+ scrollHeight : content . scrollHeight ,
562
+ } ;
552
563
553
564
if ( readingViewIs ( 'slide' ) )
554
565
{
555
- template . contentRight ( '.reading-body > div, .reading-lens > div > div' ) . css ( {
556
- ' width' : ( contentWidth * indexNum ) + 'px' ,
557
- ' height' : content . height ( ) ,
566
+ dom . this ( contentRight ) . find ( '.reading-body > div, .reading-lens > div > div' ) . css ( {
567
+ width : ( rect . width * indexNum ) + 'px' ,
568
+ height : rect . height ,
558
569
} ) ;
559
570
}
560
571
else if ( readingViewIs ( 'scroll' ) )
561
572
{
562
- template . contentRight ( '.reading-body > div' ) . css ( {
563
- ' width' : '100%' ,
573
+ dom . this ( contentRight ) . find ( '.reading-body > div' ) . css ( {
574
+ width : '100%' ,
564
575
} ) ;
565
576
566
- template . contentRight ( '.reading-lens > div > div' ) . css ( {
567
- ' width' : ( $ ( '.content-right' ) . width ( ) ) + 'px' ,
577
+ dom . this ( contentRight ) . find ( '.reading-lens > div > div' ) . css ( {
578
+ width : rect . width + 'px' ,
568
579
} ) ;
569
580
}
570
581
@@ -573,7 +584,7 @@ function calculateView()
573
584
imagesPosition = [ ] ;
574
585
imagesFullPosition = [ ] ;
575
586
576
- let scrollTop = content . scrollTop ( ) - content . offset ( ) . top ;
587
+ let scrollTop = content . scrollTop - rect . top ;
577
588
578
589
for ( let key1 in imagesDistribution )
579
590
{
@@ -859,13 +870,13 @@ function goToIndex(index, animation = true, nextPrevious = false, end = false)
859
870
860
871
clearTimeout ( disableOnScrollST ) ;
861
872
862
- disableOnScroll ( 1 ) ;
873
+ disableOnScroll ( true ) ;
863
874
864
875
disableOnScrollST = setTimeout ( function ( ) {
865
876
866
- reading . disableOnScroll ( 2 ) ;
877
+ reading . disableOnScroll ( false ) ;
867
878
868
- } , animationDurationMS ) ;
879
+ } , animationDurationMS + 200 ) ; // Add 200 of margin to avoid errors
869
880
870
881
content . stop ( true ) . animate ( { scrollTop : ( scrollTop + scrollSum ) + 'px' } , animationDurationMS ) ;
871
882
}
@@ -1250,7 +1261,7 @@ function applyScale(animation = true, scale = 1, center = false, zoomOut = false
1250
1261
if ( config . readingGlobalZoom && readingViewIs ( 'scroll' ) )
1251
1262
{
1252
1263
zoomingIn = true ;
1253
- disableOnScroll ( 1 ) ;
1264
+ disableOnScroll ( true ) ;
1254
1265
1255
1266
if ( originalRect === false )
1256
1267
{
@@ -1324,7 +1335,7 @@ function applyScale(animation = true, scale = 1, center = false, zoomOut = false
1324
1335
scalePrevData . tranY = translateY ;
1325
1336
1326
1337
calculateView ( ) ;
1327
- disableOnScroll ( 2 ) ;
1338
+ disableOnScroll ( false ) ;
1328
1339
zoomingIn = false ;
1329
1340
1330
1341
if ( scale == 1 )
@@ -1780,12 +1791,9 @@ function readingViewIs(value)
1780
1791
1781
1792
var activeOnScroll = true ;
1782
1793
1783
- function disableOnScroll ( mode )
1794
+ function disableOnScroll ( disable = true )
1784
1795
{
1785
- if ( mode == 1 )
1786
- activeOnScroll = false ;
1787
- else
1788
- activeOnScroll = true ;
1796
+ activeOnScroll = ! disable ;
1789
1797
}
1790
1798
1791
1799
function setReadingDragScroll ( dragScroll )
@@ -3290,81 +3298,69 @@ async function read(path, index = 1, end = false, isCanvas = false)
3290
3298
$ ( window ) . on ( 'mousewheel touchstart keydown' , function ( e ) {
3291
3299
3292
3300
if ( ! zoomingIn && ( e . type != 'keydown' || ( e . type == 'keydown' && ( e . keyCode == 38 || e . keyCode == 40 ) ) ) )
3293
- disableOnScroll ( 2 ) ;
3301
+ disableOnScroll ( false ) ;
3294
3302
3295
3303
} ) ;
3296
3304
3297
3305
template . contentRight ( ) . children ( 'div' ) . on ( 'scroll' , function ( e ) {
3298
3306
3299
3307
if ( activeOnScroll && readingViewIs ( 'scroll' ) )
3300
3308
{
3301
- previousScrollTop = $ ( this ) . scrollTop ( ) ;
3302
- let contentHeight = template . contentRight ( ) . children ( 'div' ) . height ( ) ;
3303
- let contentPosition = ( previousScrollTop + ( contentHeight / 2 ) ) ,
3304
- contentPositionTop = previousScrollTop ,
3305
- contentPositionBottom = previousScrollTop + contentHeight ;
3309
+ let scrollTop = this . scrollTop ;
3310
+
3311
+ let center = 0 ;
3306
3312
3307
- let selIndex = false , selPosition = false ;
3313
+ let availableScroll = rightSize . scrollHeight - rightSize . height ;
3314
+ let centerOffset = ( availableScroll < rightSize . height ? availableScroll : rightSize . height ) / 2 ;
3308
3315
3309
- let lastKey = imagesFullPosition . length - 1 ;
3316
+ if ( scrollTop < centerOffset )
3317
+ center = scrollTop + ( centerOffset * ( scrollTop / centerOffset ) ) ;
3318
+ else if ( scrollTop + centerOffset > availableScroll )
3319
+ center = scrollTop + centerOffset + ( centerOffset * ( 1 - ( availableScroll - scrollTop ) / centerOffset ) ) ;
3320
+ else
3321
+ center = scrollTop + centerOffset ;
3322
+
3323
+ let selIndex = false ;
3324
+ let closest = false ;
3310
3325
3311
3326
toBreak:
3312
3327
for ( let key1 in imagesFullPosition )
3313
3328
{
3314
3329
for ( let key2 in imagesFullPosition [ key1 ] )
3315
3330
{
3316
- if ( key1 == 0 && imagesFullPosition [ key1 ] [ key2 ] . center - contentPositionTop > 0 )
3317
- {
3318
- selIndex = key1 ;
3331
+ let position = imagesFullPosition [ key1 ] [ key2 ] ;
3319
3332
3320
- break toBreak;
3321
- }
3322
- else if ( key1 == lastKey && imagesFullPosition [ key1 ] [ key2 ] . center - contentPositionBottom < 0 )
3333
+ if ( position . top < center && position . bottom > center )
3323
3334
{
3324
- selIndex = key1 ;
3325
-
3335
+ selIndex = + key1 ;
3326
3336
break toBreak;
3327
3337
}
3328
3338
else
3329
3339
{
3330
- var position = 0 ;
3331
-
3332
- if ( Math . abs ( contentPosition - imagesFullPosition [ key1 ] [ key2 ] . top ) < Math . abs ( contentPosition - imagesFullPosition [ key1 ] [ key2 ] . bottom ) )
3333
- position = imagesFullPosition [ key1 ] [ key2 ] . top // + 16;
3334
- else
3335
- position = imagesFullPosition [ key1 ] [ key2 ] . bottom // - 16;
3336
-
3337
- position = Math . abs ( contentPosition - position ) ;
3340
+ let diff = Math . abs ( position . center - center ) ;
3338
3341
3339
- if ( ! selIndex || position < selPosition )
3342
+ if ( closest === false || diff < closest . diff )
3340
3343
{
3341
- selIndex = key1 ;
3342
- selPosition = position ;
3343
- }
3344
- else if ( selIndex && position > selPosition )
3345
- {
3346
- break toBreak;
3344
+ selIndex = + key1 ;
3345
+ closest = { center : position . center , diff : diff } ;
3347
3346
}
3348
3347
}
3349
3348
}
3350
3349
}
3351
3350
3352
- var imgHeight = imagesFullPosition [ selIndex ] [ 0 ] . bottom - imagesFullPosition [ selIndex ] [ 0 ] . top + ( _config . readingMargin . top * 2 ) ;
3351
+ let imgHeight = imagesFullPosition [ selIndex ] [ 0 ] . bottom - imagesFullPosition [ selIndex ] [ 0 ] . top + ( _config . readingMargin . top * 2 ) ;
3353
3352
3354
- var pageVisibility = Math . floor ( imgHeight / contentHeight ) ;
3353
+ let pageVisibility = Math . floor ( imgHeight / rightSize . height ) ;
3355
3354
3356
3355
maxPageVisibility = pageVisibility ;
3357
3356
3358
- if ( pageVisibility > 0 )
3359
- var contentHeightRes = ( ( contentHeight * pageVisibility ) - imgHeight ) / pageVisibility ;
3360
- else
3361
- var contentHeightRes = 0 ;
3357
+ let contentHeightRes = pageVisibility > 0 ? ( ( rightSize . height * pageVisibility ) - imgHeight ) / pageVisibility : 0 ;
3362
3358
3363
- scrollPart = ( ( contentHeight - contentHeightRes ) - contentHeight / pageVisibility ) ;
3359
+ scrollPart = ( ( rightSize . height - contentHeightRes ) - rightSize . height / pageVisibility ) ;
3364
3360
3365
3361
currentPageVisibility = Math . round ( ( previousScrollTop - ( imagesFullPosition [ selIndex ] [ 0 ] . top - _config . readingMargin . top ) ) / scrollPart ) ;
3366
3362
3367
- if ( currentIndex != ( parseInt ( selIndex ) + 1 ) )
3363
+ if ( currentIndex != selIndex + 1 )
3368
3364
{
3369
3365
if ( currentScale != 1 && ! ( config . readingGlobalZoom && readingViewIs ( 'scroll' ) ) )
3370
3366
reading . resetZoom ( ) ;
@@ -3394,8 +3390,10 @@ async function read(path, index = 1, end = false, isCanvas = false)
3394
3390
goToImageCL ( imageIndex , true ) ;
3395
3391
}
3396
3392
3397
- currentIndex = parseInt ( selIndex ) + 1 ;
3393
+ currentIndex = selIndex + 1 ;
3398
3394
}
3395
+
3396
+ previousScrollTop = scrollTop ;
3399
3397
}
3400
3398
3401
3399
} ) ;
@@ -3586,4 +3584,5 @@ module.exports = {
3586
3584
setShownBarHeader : function ( value ) { shownBarHeader = value } ,
3587
3585
loadReadingMoreOptions : loadReadingMoreOptions ,
3588
3586
currentScale : function ( ) { return currentScale } ,
3587
+ rightSize : function ( ) { return rightSize } ,
3589
3588
} ;
0 commit comments