Created
March 15, 2014 13:15
-
-
Save xavortm/9567041 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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