@@ -25,6 +25,7 @@ const findCurrentPageIndex = (wrapper: HTMLDivElement): number => {
25
25
// TODO: make configurable?
26
26
const SCROLL_SAFE_ZONE = 5 ; // px
27
27
const SCROLL_OFFSET = 0.95 ;
28
+ const SCROLL_OFFSET_SLIGHT = 0.25 ;
28
29
const SCROLL_BEHAVIOR : ScrollBehavior = 'smooth' ;
29
30
30
31
const isAtBottom = ( ) => {
@@ -111,7 +112,7 @@ export function VerticalPager(props: IReaderProps) {
111
112
} , [ selfRef ] ) ;
112
113
113
114
const go = useCallback (
114
- ( direction : 'up' | 'down' ) => {
115
+ ( direction : 'up' | 'down' , offset : number = SCROLL_OFFSET ) => {
115
116
if ( direction === 'down' && isAtBottom ( ) ) {
116
117
nextChapter ( ) ;
117
118
return ;
@@ -123,7 +124,7 @@ export function VerticalPager(props: IReaderProps) {
123
124
}
124
125
125
126
window . scroll ( {
126
- top : window . scrollY + window . innerHeight * SCROLL_OFFSET * ( direction === 'up' ? - 1 : 1 ) ,
127
+ top : window . scrollY + window . innerHeight * offset * ( direction === 'up' ? - 1 : 1 ) ,
127
128
behavior : SCROLL_BEHAVIOR ,
128
129
} ) ;
129
130
} ,
@@ -138,11 +139,17 @@ export function VerticalPager(props: IReaderProps) {
138
139
go ( e . shiftKey ? 'up' : 'down' ) ;
139
140
break ;
140
141
case 'ArrowDown' :
142
+ e . preventDefault ( ) ;
143
+ go ( e . shiftKey ? 'up' : 'down' , SCROLL_OFFSET_SLIGHT ) ;
144
+ break ;
141
145
case 'ArrowRight' :
142
146
e . preventDefault ( ) ;
143
147
go ( e . shiftKey ? 'up' : 'down' ) ;
144
148
break ;
145
149
case 'ArrowUp' :
150
+ e . preventDefault ( ) ;
151
+ go ( e . shiftKey ? 'down' : 'up' , SCROLL_OFFSET_SLIGHT ) ;
152
+ break ;
146
153
case 'ArrowLeft' :
147
154
e . preventDefault ( ) ;
148
155
go ( e . shiftKey ? 'down' : 'up' ) ;
0 commit comments