Skip to content

Instantly share code, notes, and snippets.

@lucatironi
Created October 16, 2012 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucatironi/3899430 to your computer and use it in GitHub Desktop.
Save lucatironi/3899430 to your computer and use it in GitHub Desktop.
Fixed scrolling sidebar
// Keeps the order recap box fixed on scroll, a la Apple Store
// http://jqueryfordesigners.com/fixed-floating-elements
$(function () {
var msie6 = $.browser == 'msie' && $.browser.version < 7;
if (!msie6 && $('#sidebar').length > 0 && false) {
var top = $('#logo').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0)),
order_recap_height = $('#sidebar').height(),
order_form_wrapper_height = $('#main-content').height();
order_form_container_height = $('.main-container').height();
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
if (order_recap_height >= order_form_wrapper_height) {
$('.main-container').height(order_recap_height);
}
// whether that's below the form
if (y >= top && $(window).height() >= order_recap_height) {
// if so, ad the fixed class
$('#sidebar').addClass('fixed');
$('#logo').addClass('fixed');
$('#header-nav').addClass('fixed-logo');
$('#main-content').addClass('fixed-sidebar');
} else {
// otherwise remove it
$('#sidebar').removeClass('fixed');
$('#logo').removeClass('fixed');
$('#header-nav').removeClass('fixed-logo');
$('#main-content').removeClass('fixed-sidebar');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment