myowin76
5/21/2013 - 3:43 PM

Jquery persistent side block when scrolling

Jquery persistent side block when scrolling

var $cart = $('#mini-cart');
  if ($cart.length > 0) {
		var basket_container = $('.basket-container').position();
		
		$cart.data('limit', $cart.position().top);

		if (!($.browser.msie && $.browser.version < 7)) $cart.css('position', 'fixed');
	  
		$(window).scroll(function() {
			var $offset;
			var $scroll;

			$offset = $cart.data('limit');
			$offset = basket_container.top;

			$scroll = $(window).scrollTop();
			if ($cart.css('position') == 'fixed') {
				$cart.css('top', Math.max(15, (-$scroll + $offset)) + 'px');
			}
			else {
				$cart.css('margin-top', Math.max(15, ($scroll - $offset)) + 'px');
			}
		}).trigger('scroll');
	}