Created
August 14, 2013 12:30
-
-
Save yratof/6230626 to your computer and use it in GitHub Desktop.
$ is not defined?
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
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