File tree Expand file tree Collapse file tree 1 file changed +4
-14
lines changed Expand file tree Collapse file tree 1 file changed +4
-14
lines changed Original file line number Diff line number Diff line change 1616 </ style >
1717 < script src ="/socket.io/socket.io.js "> </ script >
1818 < script >
19-
20- var SCROLL_PADDING = 100 ;
21- var cumulativeOffset = function ( element ) {
22- var top = 0 , left = 0 ;
23- do {
24- top += element . offsetTop || 0 ;
25- left += element . offsetLeft || 0 ;
26- element = element . offsetParent ;
27- } while ( element ) ;
28- return { top : top , left : left } ;
29- } ;
30-
3119 var socket = io . connect ( 'http://' + window . location . host + '/' ) ;
3220 socket . on ( 'connect' , function ( ) {
3321 socket . on ( 'newContent' , function ( newHTML ) {
3422 document . querySelector ( ".markdown-body" ) . innerHTML = newHTML ;
35- var marker = document . querySelector ( "#marker" ) ;
23+
24+ // scroll to the hyperlink with id="marker"
25+ let marker = document . getElementById ( "marker" ) ;
3626 if ( marker ) {
37- window . scrollTo ( 0 , cumulativeOffset ( marker ) . top - SCROLL_PADDING ) ;
27+ marker . scrollIntoView ( ) ;
3828 }
3929 } ) ;
4030 socket . on ( 'die' , function ( newHTML ) {
You can’t perform that action at this time.
0 commit comments