0

I got this script

$("body, html").animate({scrollTop: $(document).height()}, 1000)

As seen above it will make so the the page is scrolled down to the documents height: aka the bottom. However in my case its too far down, I would like to scroll down to bottom:100px; or bottom:10%; Is this possible? I found examples but they didn't work for me. What am I missing to make it work?:)

1 Answers1

1

Sure, you can set the value of scrollTop to any value you can mathematically calculate:

// Top is 100 px short of bottom
$("body, html").animate({scrollTop: $(document).height() - 100}, 1000)
// 90% scroll down
$("body, html").animate({scrollTop: $(document).height() * 0.9}, 1000)

Note that for all these, 100px is very small. Your browser window would have to be <100px tall for it to NOT scroll all the way to the bottom.

You can use the visible height of the browser window in your equation too:

$(window).height()
Chase
  • 3,028
  • 14
  • 15
  • Thanks for your explenation since I was already scrolled down a bit the - 100px of height was always scrolling to the bottom, but now I understand –  May 29 '20 at 07:14