Skip to content

Commit e74cb09

Browse files
authored
Merge pull request #80 from bhomie:long-text-scroll
Scroll Longform text
2 parents 682f181 + fe1b729 commit e74cb09

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

public/js/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,18 @@ function updateCaretPosition() {
371371
left: newLeft
372372
}, duration)
373373

374+
let browserHeight = window.innerHeight;
375+
let middlePos = (browserHeight / 2) - $("#caret").outerHeight()/2;
376+
let contentHeight = document.body.scrollHeight;
377+
378+
if (newTop >= middlePos && contentHeight > browserHeight) {
379+
window.scrollTo({
380+
left: 0,
381+
top: newTop - middlePos,
382+
behavior: 'smooth'
383+
})
384+
}
385+
374386
}
375387

376388
function countChars() {

0 commit comments

Comments
 (0)