$.fn.fuckingAwesome = function( options ) { var self = this, win = $( window ); options = $.extend( { min: 0 }, options ); if ( options.min === "auto" ) { options.min = self.offset().top; } win.bind( "scroll resize", function() { var windowTop = win.scrollTop(), currentTop = self.offset().top; if ( windowTop > options.min || currentTop > options.min ) { var top = Math.max( windowTop, options.min ); if ( options.max ) { top = Math.min( top, $.isFunction(options.max) ? options.max() : options.max ); } self.stop().animate({ top: top }, 200); } }); };