You will have to do something similar to what Ozzu does. You will notice that at times the menu on the right is a fixed element if the page is long enough, but as soon as the footer approaches it turns back to not being fixed to not scroll over the footer. The only way to achieve this is using Javascript. In the case of Ozzu we use jQuery to make this easier. Basically you just need to custom write some code to detect when the fixed element should be fixed and when it should not be fixed.
There are probably numerous ways to do this, but how we currently do this is as follows:
//Enables the dynamic static menu
var triggerY, triggerY2;
IntializeScrollTriggers();
$(window).resize(function() {
IntializeScrollTriggers();
});
$(window).scroll(function (event) {
scrollCompute();
});
function scrollCompute()
{
if($('#container').height() > $('#sidebar').height()) {
if(($('#sidebar').height() + 10)> $(this).height()) {
triggerY2 = $('#container').offset().top + $('#container').height() - parseFloat($('#container').css('marginTop').replace(/auto/, 0));
var scrollY = $(this).scrollTop() + $(this).height();
if (scrollY >= triggerY) {
$('#sidebar').addClass('fixed').css('left', parseFloat($('#content').width()) + 10);
if(scrollY >= triggerY2) {
$('#sidebar').css('bottom', scrollY - triggerY2);
}
else {
$('#sidebar').css('bottom', '0px');
}
} else {
$('#sidebar').removeClass('fixed').css('left', '').css('bottom', '');
}
}
else {
var scrollY = $(this).scrollTop();
if (scrollY >= triggerY) {
$('#sidebar').addClass('fixed').css('left', parseFloat($('#content').width()) + 10).css('top', '10px');
}
else {
$('#sidebar').removeClass('fixed').css('left', '').css('top', '');
}
}
}
}
function IntializeScrollTriggers() {
$('#sidebar').removeClass('fixed').css('left', '').css('bottom', '').css('top', '');
if(($('#sidebar').height() + 10) > $(this).height()) {
triggerY2 = $('#container').offset().top + $('#container').height() - parseFloat($('#container').css('marginTop').replace(/auto/, 0));
triggerY = $('#sidebar').offset().top + $('#sidebar').height() - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
}
else {
triggerY = $('#sidebar').offset().top - 10 - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
}
scrollCompute();
}
- //Enables the dynamic static menu
- var triggerY, triggerY2;
- IntializeScrollTriggers();
-
- $(window).resize(function() {
- IntializeScrollTriggers();
- });
-
- $(window).scroll(function (event) {
- scrollCompute();
- });
-
- function scrollCompute()
- {
- if($('#container').height() > $('#sidebar').height()) {
- if(($('#sidebar').height() + 10)> $(this).height()) {
- triggerY2 = $('#container').offset().top + $('#container').height() - parseFloat($('#container').css('marginTop').replace(/auto/, 0));
- var scrollY = $(this).scrollTop() + $(this).height();
- if (scrollY >= triggerY) {
- $('#sidebar').addClass('fixed').css('left', parseFloat($('#content').width()) + 10);
- if(scrollY >= triggerY2) {
- $('#sidebar').css('bottom', scrollY - triggerY2);
- }
- else {
- $('#sidebar').css('bottom', '0px');
- }
- } else {
- $('#sidebar').removeClass('fixed').css('left', '').css('bottom', '');
- }
- }
- else {
- var scrollY = $(this).scrollTop();
- if (scrollY >= triggerY) {
- $('#sidebar').addClass('fixed').css('left', parseFloat($('#content').width()) + 10).css('top', '10px');
- }
- else {
- $('#sidebar').removeClass('fixed').css('left', '').css('top', '');
- }
- }
- }
- }
-
- function IntializeScrollTriggers() {
- $('#sidebar').removeClass('fixed').css('left', '').css('bottom', '').css('top', '');
-
- if(($('#sidebar').height() + 10) > $(this).height()) {
- triggerY2 = $('#container').offset().top + $('#container').height() - parseFloat($('#container').css('marginTop').replace(/auto/, 0));
- triggerY = $('#sidebar').offset().top + $('#sidebar').height() - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
- }
- else {
- triggerY = $('#sidebar').offset().top - 10 - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
- }
-
- scrollCompute();
- }
That might give you ideas on how to do it, you will likely have to custom write your own solution but with the above that might give you an idea of how to get started. Remember this is dependent on the jQuery library.
Ozzu Hosting - Want your website on a fast server like Ozzu?