Fixed Sidebar With Relative Height And Fluid Absolute Transitioning
I am looking to achieve a fixed sidebar that will scroll to the bottom of the div and then will change into an absolutely positioned element in order to stop it continuing down the
Solution 1:
I amended this by editing the code used for calculating the scroll distance:
$(window).bind('scroll', function() {
if($(window).scrollTop() >= offsetHeight - 100) {
$('.sidebar-wrap').addClass('scroll');
} else {
$('.sidebar-wrap').removeClass('scroll');
}
});
Because we already know the offsetHeight is equal to that of the sidebar height, I then messed around with subtracting values until it was fluent. If you was to use this code I believe you would have to change the value of - 100 in order to make it work.
EDIT: I made it all into 1 function and enabled everything to update on window resize which also only fires once the resize is complete.
<scripttype="text/javascript">
$(document).ready(function() {
functionupdateScroll() {
var offsetHeight = document.getElementById('main-column').offsetHeight;
document.getElementById('main-sidebar').style.height = offsetHeight+'px';
$(window).bind('scroll', function() {
if($(window).scrollTop() >= offsetHeight - 100) {
$('.sidebar-wrap').addClass('scroll');
} else {
$('.sidebar-wrap').removeClass('scroll');
}
});
}
$(window).resize(updateScroll).trigger('resize')
});
</script>
Post a Comment for "Fixed Sidebar With Relative Height And Fluid Absolute Transitioning"