Skip to content

Instantly share code, notes, and snippets.

@yratof
Created August 14, 2013 12:30
Show Gist options
  • Save yratof/6230626 to your computer and use it in GitHub Desktop.
Save yratof/6230626 to your computer and use it in GitHub Desktop.
$ is not defined?
jQuery(document).ready(function ($) {
$.fn.scrollBottom = function() {
return $(document).height() - this.scrollTop() - this.height();
};
jQuery(window).scroll(function ($) {
var offset = $('#main').offset(); //<--- Top of the element where the scroll should start
var docViewTop = $(window).scrollTop();//<--- Top of the window
var docViewBottom = docViewTop + $(window).height(); //<--- Bottom of the window
var elemTop = $('#footer').offset().top; // <-- This is the top of the element that we are testing if it has come into view
if ($(window).scrollTop() > offset.top && docViewBottom < elemTop) { //<-- This adds the floating class if the top of the window reaches the element and the other element is not in view
$('.breadcrumbs').addClass('fixed');
} else {
$('.breadcrumbs').removeClass('fixed');
}
$(window).unbind('scroll');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment