File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,35 @@ class Game extends React.Component {
31
31
componentDidMount ( ) {
32
32
this . init ( this . state . src ) ;
33
33
}
34
+ componentDidUpdate ( ) {
35
+ this . adjustHistoryScroll ( )
36
+ }
37
+ adjustHistoryScroll ( ) {
38
+ const history = document . querySelector ( ".history" ) ;
39
+ const move = history . querySelector ( ".current-move" )
40
+ if ( ! move ) {
41
+ history . scroll ( 0 , 0 ) ;
42
+ return ;
43
+ }
44
+
45
+ const viewBox = {
46
+ bottom : history . offsetTop + history . offsetHeight ,
47
+ top : history . offsetTop + history . scrollTop
48
+ }
49
+ const moveBox = {
50
+ bottom : move . offsetTop + move . offsetHeight ,
51
+ top : move . offsetTop
52
+ }
53
+
54
+
55
+ if ( moveBox . bottom > viewBox . bottom ) {
56
+ history . scrollBy ( 0 , moveBox . bottom - viewBox . bottom ) ;
57
+ }
58
+ if ( moveBox . top < viewBox . top ) {
59
+ history . scrollBy ( 0 , moveBox . top - viewBox . top )
60
+ }
61
+
62
+ }
34
63
init ( pgn ) {
35
64
if ( ! pgn ) {
36
65
return
You can’t perform that action at this time.
0 commit comments