Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save ramiabraham/e035eb34b237e16b84e5 to your computer and use it in GitHub Desktop.

Select an option

Save ramiabraham/e035eb34b237e16b84e5 to your computer and use it in GitHub Desktop.
sticky div (typically a sidebar) with compat for touch devices
(function($) {
$(window).bind("load", function() {
var sidebar_one = $('#sidebar-1' );
var sidebar_two = $('#sidebar-2');
$( window ).scroll( function() {
if ( $(this).scrollTop() > 660 && $(this).width() > 1024 ) {
sidebar_one.addClass( 'fixed' );
sidebar_two.addClass( 'fixed' );
} else {
sidebar_one.removeClass( 'fixed' );
sidebar_two.removeClass( 'fixed' );
}
});
} );
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment