I have a div box (called flux) with a variable amount of content inside. This divbox has overflow set to auto.
Now, what I am trying to do, is, when the use scroll t
not sure if it is any help but this is how I do it.
I have an index panel that is larger that the window and I let it scroll until the end this index is reached. Then I fix it in position. The process is reversed once you scroll toward the top of the page.
Regards.
<style type="text/css">
.fixed_Bot {
position: fixed;
bottom: 24px;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
var sidebarheight = $('#index').height();
var windowheight = $(window).height();
$(window).scroll(function () {
var scrollTop = $(window).scrollTop();
if (scrollTop >= sidebarheight - windowheight){
$('#index').addClass('fixed_Bot');
}
else {
$('#index').removeClass('fixed_Bot');
}
});
});
</script>
If you need to use this on a div that has overflow-y as hidden or scroll, something like this may be what you need.
if ($('#element').prop('scrollHeight') - $('#element').scrollTop() <= Math.ceil($('#element').height())) {
at_bottom = true;
}
I found ceil was needed because prop scrollHeight seems to round, or perhaps some other reason causing this to be off by less than 1.
I found a solution that when you scroll your window and end of a div shown from bottom gives you an alert.
$(window).bind('scroll', function() {
if($(window).scrollTop() >= $('.posts').offset().top + $('.posts').outerHeight() - window.innerHeight) {
alert('end reached');
}
});
In this example if you scroll down when div (.posts
) finish its give you an alert.