ricardozea
5/13/2013 - 6:01 PM

jQuery script to make items stick to the top of the browser when scrolling down, ie: a nav bar.

jQuery script to make items stick to the top of the browser when scrolling down, ie: a nav bar.

//Sticky items
var $stickyItem = $('.sticky-item'); //Element that will get stuck
var $stickyTarget = $('.sticky-target'); //Element that when scrolled over will trigger the above element to stick

$(window).scroll(function() {
	if ($(this).scrollTop() > $header.offset().top + $header.height()) {
		$sticky.addClass('stuck').removeClass('unstuck');
		//$('#main-container').addClass('top-space');
	} else {
		$sticky.removeClass('stuck').addClass('unstuck');
		//$('#main-container').removeClass('top-space');
	}
});