Reputation: 117
I want to get the bottom position of the visible part of the document, not the height of document.
For example, my screen height is 768px
then the height of visible part is about 650px
, if the scroll height is 200px
then the bottom position will be around 850px
. I tried using $(window).height()
but it returns the height of the document.
Upvotes: 10
Views: 23079
Reputation: 337560
To achieve this you just need to add the scrollTop()
of the window
to its height()
within the scroll()
event handler, like this:
$(window).scroll(function() {
$('.foo').text($(window).scrollTop() + $(window).height());
}).scroll();
body {
padding: 0;
margin: 0;
}
.content {
height: 30000px;
}
.foo {
position: fixed;
top: 10px;
left: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="content"></div>
<div class="foo"></div>
Upvotes: 8