/** * jQuery.absoluteToFixed * * Copyright (C) 2010 Marcos Cooper * Dual licensed under MIT and GPL * * @author Marcos Cooper * @date 2011-10-28 * @version 0.3 */ (function($){ $.fn.absoluteToFixed = function(options) { var settings = $.extend( { 'center' : false }, options); if (!jQuery.browser.msie || jQuery.browser.version >= 7) { return this.each(function(){ var target = $(this); var offset = target.offset(); var center = 0; if (settings.center) { center = Math.floor($(window).height() / 2) - Math.floor(target.height() / 2); } $(window).scroll(function() { if ($(window).scrollTop() > (offset.top - center)) { target.css({'position': 'fixed', 'top': center}); } else { target.attr('style', ''); } }); $(window).resize(function(){ if (settings.center) { center = Math.floor($(window).height() / 2) - Math.floor(target.height() / 2); } }); }); } } })(jQuery);