timmack
timmack

Reputation: 590

How to scroll down to 90% of your document or body's height?

I want to scroll down to particularly 90% of my document or body's height, not the screen height of the device. I understand that this example below would scroll down to a certain element of my page or document.

$("html, body").animate({ scrollTop: $("#emptydisplay").offset().top }, 500);

but that is not what I need. I need to scroll down automatically to 90% of whatever my HTML document's height might be. I tried something like this

 $('html,body').animate({ scrollTop: $(document).height() * 0.90 });

but it's scrolling down all the way to the bottom.

How do I do this in jquery? Thanks...

Upvotes: 1

Views: 1936

Answers (3)

Nageshwar Reddy Pandem
Nageshwar Reddy Pandem

Reputation: 1047

you should remove the window height from document height

$('html,body').animate({ scrollTop: ($(document).height() * 0.90)-$(window).height() });

Upvotes: 2

klenium
klenium

Reputation: 2607

scrollTop means the top side of your window. scrollTop: 100% means full height of the page - the height of the window. If you want 90%, you need this:

$('html,body').animate({ scrollTop: $(document).height() * 0.9 - $(window).height() }, 500);

Upvotes: 2

MagicJuly
MagicJuly

Reputation: 473

you should minus window's height

 $('html,body').animate({ scrollTop: $(document).height() * 0.90 - $(window).height() });

Upvotes: 1

Related Questions