Skip to content

Instantly share code, notes, and snippets.

@xavortm
Created March 15, 2014 13:15
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 xavortm/9567041 to your computer and use it in GitHub Desktop.
Save xavortm/9567041 to your computer and use it in GitHub Desktop.
/**
* Sticky area - stick date titles to top
* @param stickies
*/
function stickyTitles(stickies) {
var self = this,
isLoaded = false;
console.log(stickies);
this.load = function() {
stickies.each(function(){
var thisSticky = jQuery(this);
if(!self.isLoaded) {
thisSticky.wrap('<div class="followWrap" />');
thisSticky.parent().height(thisSticky.outerHeight());
}
jQuery.data(thisSticky[0], 'pos', thisSticky.offset().top);
});
self.isLoaded = true;
}
this.scroll = function() {
var offsetTop = (parseInt(jQuery(document.body).css('padding-top')) || 0) + 33, // 33px allocated by nav-tabs
isFloating = false;
stickies.each(function(i){
var thisSticky = jQuery(this),
pos = thisSticky.hasClass('fixed')
? jQuery.data(thisSticky[0], 'pos')
: thisSticky.offset().top;
jQuery.data(thisSticky[0], 'pos', pos);
pos -= offsetTop;
if (pos <= jQuery(window).scrollTop()) {
if(!thisSticky.hasClass('fixed')) {
thisSticky.prepend(jQuery('.schedule > .nav-tabs').clone(true));
}
thisSticky.addClass("fixed container");
} else {
if(thisSticky.hasClass('fixed')) {
thisSticky.find('.nav-tabs').remove();
}
thisSticky.removeClass("fixed container");
}
});
if(isFloating) {
jQuery('.schedule').addClass('floating');
}
else {
jQuery('.schedule').removeClass('floating');
}
}
}
jQuery(document).ready(function(){
var newStickies = new stickyTitles(jQuery(".day-floating"));
newStickies.load();
jQuery(window).on("resize", newStickies.load);
jQuery(window).on("scroll", newStickies.scroll);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment