Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何向下滚动到文档或身体高度的90%?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如何向下滚动到文档或身体高度的90%?

Javascript 如何向下滚动到文档或身体高度的90%?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想向下滚动到文档或正文高度的90%,而不是设备屏幕高度的90%。我知道下面的示例将向下滚动到我的页面或文档的某个元素 $("html, body").animate({ scrollTop: $("#emptydisplay").offset().top }, 500); 但这不是我需要的。我需要自动向下滚动到HTML文档高度的90%。我试过这样的东西 $('html,body').animate({ scrollTop: $(document).height() * 0.90 });

我想向下滚动到文档或正文高度的90%,而不是设备屏幕高度的90%。我知道下面的示例将向下滚动到我的页面或文档的某个元素

$("html, body").animate({ scrollTop: $("#emptydisplay").offset().top }, 500);
但这不是我需要的。我需要自动向下滚动到HTML文档高度的90%。我试过这样的东西

 $('html,body').animate({ scrollTop: $(document).height() * 0.90 });
但它一直向下滚动到底部


在jquery中如何实现这一点?谢谢…

你应该减去窗户的高度

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

你应该减去窗户的高度

 $('html,body').animate({ scrollTop: $(document).height() * 0.90 - $(window).height() });
scrollTop表示窗口的顶部。scrollTop:100%表示页面的全高-窗口的高度。如果您想要90%,您需要:

$('html,body').animate({ scrollTop: $(document).height() * 0.9 - $(window).height() }, 500);
scrollTop表示窗口的顶部。scrollTop:100%表示页面的全高-窗口的高度。如果您想要90%,您需要:

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

您应该从文档高度中删除窗口高度

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

您应该从文档高度中删除窗口高度

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

使用BodyHight窗口高度的90%您可以设置小提琴/jsbin吗?我看到它在工作fine@mohamedrias我不知道为什么它会在你的小提琴上起作用,但在我的页面上,它不会像我预期的那样起作用。但现在已经解决了。感谢所有的帮助…干杯使用90%的Bodyhight窗口高度您能设置小提琴/jsbin吗?我看到它在工作fine@mohamedrias我不知道为什么它会在你的小提琴上起作用,但在我的页面上,它不会像我预期的那样起作用。但现在已经解决了。感谢所有提供帮助的人…仅在本页中打开控制台并进行测试仅在本页中打开控制台并进行测试