Created
October 16, 2012 13:55
-
-
Save lucatironi/3899430 to your computer and use it in GitHub Desktop.
Fixed scrolling sidebar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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