How to scroll an element into center of window when it's the "last element" on the page

I have a bunch of div elements that contain text and inputs. The first div is always visible. Whenever a div‘s input changes, next div becomes visible. I want to automatically scroll down the window as these new divs become visible, preferably having the last visible div in the vertical-center of the screen.

element.scrollIntoView({block: 'center'}) generally works, but it makes the top of the last visible div at the bottom of the window, so the user is forced to scroll further to see the inputs inside the div. I want the last div‘s top to be in the center of the window and have empty space underneath the div until the next div is revealed. Is there a way to do this?

146 thoughts on “How to scroll an element into center of window when it's the "last element" on the page”

  1. Pingback: viagra price
  2. Pingback: cialis alternative
  3. Pingback: cialis usa
  4. Pingback: sildenafil citrate
  5. Pingback: sale cialis
  6. Pingback: womens viagra
  7. Pingback: viagra buy
  8. Pingback: sildenafil
  9. Pingback: viagra online usa
  10. Pingback: viagra for sell
  11. Pingback: 20mg cialis daily
  12. Pingback: usa viagra pills
  13. Pingback: cialis mastercard
  14. Pingback: tadalafil cialis
  15. Pingback: sildenafil 50 mg
  16. Pingback: viagra pills
  17. Pingback: viagra alternative
  18. Pingback: viagra gum
  19. Pingback: female viagra
  20. Pingback: bestellen viagra
  21. Pingback: viagra tablet
  22. Pingback: viagra substitute
  23. Pingback: viagra en ligne
  24. Pingback: viagra pornhub
  25. Pingback: viagra prices
  26. Pingback: sildenafil price
  27. Pingback: sildenafil goodrx
  28. Pingback: hims viagra

Leave a Comment