mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Fixed calculating if reply form is in viewport
This commit is contained in:
parent
e130c2edcd
commit
24f384b0a2
1 changed files with 9 additions and 2 deletions
|
@ -158,15 +158,22 @@ const Form = (props) => {
|
|||
if (props.isReply) {
|
||||
timer = setTimeout(() => {
|
||||
// Is the form already in view?
|
||||
const formHeight = 100;
|
||||
const formHeight = formEl.current.offsetHeight;
|
||||
|
||||
// Start y position of the form
|
||||
const yMin = getScrollToPosition();
|
||||
|
||||
// Y position of the end of the form
|
||||
const yMax = yMin + formHeight;
|
||||
|
||||
// Trigger scrolling when yMin and yMax is closer than this to the border of the viewport
|
||||
const offset = 64;
|
||||
|
||||
const viewportHeight = window.innerHeight;
|
||||
const viewPortYMin = window.scrollY;
|
||||
const viewPortYMax = viewPortYMin + viewportHeight;
|
||||
|
||||
if (yMin < viewPortYMin || yMax > viewPortYMax) {
|
||||
if (yMin - offset < viewPortYMin || yMax + offset > viewPortYMax) {
|
||||
// Center the form in the viewport
|
||||
const yCenter = (yMin + yMax) / 2;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue